Assignments
Assignments
Assignments
Rani:
Assignment 1: Take the number from end user check it is even or odd?
import java.util.Scanner;
class FlowControlStatements
{ public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter a num:");
int num = s.nextInt();
if (num%2==0)
{ System.out.println("Number is Even....");
}
else
{ System.out.println("Number is Odd....");
}
s.close();
}
}
O/P:
Enter a num:
09
Number is Odd....
Assignment 2: Take the two numbers from end user print the bigger number?
import java.util.Scanner;
class FlowControlStatements
{ public static void main(String[] args)
{
if (num1>num2)
{ System.out.println("Number1 is Greater...."+num1);
}
else
{ System.out.println("Number2 is Greater."+num2);
}
s.close();
}
}
O/P:
Enter a num1:
66
Enter a num2:
88
Number2 is Greater.88
Assignment 3: Take the year from end user check it is leap year or not?
import java.util.Scanner;
class FlowControlStatements
{ public static void main(String[] args)
{
int year;
Scanner s = new Scanner(System.in);
System.out.println("Enter year");
year = s.nextInt();
else {
O/P:
Enter year
2000
2000 : Leap Year
Assignment 4: Take the user name & password from end user.
Check the condition print the the message login Success or
fail.
import java.util.Scanner;
class FlowControlStatements
{ public static void main(String[] args)
{
String uname;
String pwd;
Scanner s = new Scanner(System.in);
System.out.println("Enter user name:");
uname = s.next();
System.out.println("Enter password");
pwd=s.next();
else {
System.out.println("Login fail");
}
}
}
//O/P:Enter user name:
// Rani
// Enter password
// PASSWORD
// login is success Rani
Assignment-5: what is the difference between next() & nextLine() write one
example.
s.next() : It read input from the input device till the space character.
s.nextLine() : It read input from the input device till the line
change.
class FlowControlStatements
{
static int num1=22,num2=12;
static void add()
{
System.out.println(FlowControlStatements.num1+FlowControlStatements.num2);
}
static void mul()
{
System.out.println(FlowControlStatements.num1*FlowControlStatements.num2);
}
public static void main(String[] args)
{
FlowControlStatements.add();
FlowControlStatements.mul();
}
}
class FlowControlStatements
{
int num1=40;
int num2=70;
static void add()
{
FlowControlStatements t=new FlowControlStatements();
System.out.println(t.num1+t.num2);
}
static void mul()
{ FlowControlStatements t=new FlowControlStatements();
System.out.println(t.num1*t.num2);
}
public static void main(String[] args)
{
FlowControlStatements.add();
FlowControlStatements.mul();
}
}
class FlowControlStatements
{
public static void main(String[] args)
{
Services s=new Services();
s.voteRegister("Rekha","hyderabad",90309464,19,741258); // call
the voteRegister by passing the argument.
Services.marry("Ram",100,10000.00);// call the marry method by
passing the arguments.
}
}
package com.ratan.sessions;
class Services
{
String name;
String location;
long mobile;
long age;
long sscRoolNo;
if(age>18)
{
if(location=="hyderabad")
{
long res=mobile+sscRoolNo+age;
System.out.println("Eligible for voting"+res);
//System.out.println(mobile+sscRoolNo+age);
}
else
{
System.out.println("Location doesn't support");
}
}
else
{
System.out.println("Age doesn't support"+age);
}
}
static void marry(String mname,int mage,double bankBalance)
{
if(mage>=18 && mage<=34)
{
System.out.println("Eligible for marriage" +mage);
}
else if (mage<18)
{
System.out.println("not eligible try after some time "
+mage);
}
else
{
System.out.println("Sorry your tooooo late ..... " +mage);
}
}
}
26-04-2021
package com.tcs.data.instancedata;
package com.tcs.data.staticdata;
}
}
package com.tcs.data.client;
import com.tcs.data.instancedata.Test;
import com.tcs.data.staticdata.Demo;
Demo.companyName("TCS");
}
Siva kumar:
Usman:
Guru Assignment:-
Assignment 1: Take the number from end user check it is even or odd?
Ans:-
=====
package Guru.Rat.Com;
import java.util.Scanner;
public class OddEven {
public static void main(String[] args){
Scanner s=new Scanner(System.in);
if (num %2 == 0)
{
System.out.println("The Given Number "+num+" is even number");
}
else
System.out.println("The Given Number "+num+" is Odd number");
s.close();
}
Assignment 2: Take the two numbers from end user print the bigger number?
Ans:-
====
package Guru.Rat.Com;
import java.util.Scanner;
public class BigNum {
public static void main(String[] args){
Scanner s=new Scanner(System.in);
Assignment 3: Take the year from end user check it is leap year or not?
Ans
===
package Guru.Rat.Com;
import java.util.Scanner;
public class LeapOrNot {
}
}
Assignment 4: Take the user name & password from end user.
Check the condition print the the message login Success or
fail.
Ans
===
package Guru.Rat.Com;
import java.util.Scanner;
public class UserPwdCheck {
public static void main (String[] args){
Scanner s=new Scanner(System.in);
System.out.println("Enter a user Name:- ");
String uname=s.next();
System.out.println("Enter a password:- ");
String upwd=s.next();
Assignment-5: what is the difference between next() & nextLine() write one
example.
Ans
====
s.next() : to read the String data --> Next is
print upto space from the input
s.nextLine() : to read the String data. --> NextLine
is print until the line end with space words
package Guru.Rat.Com;
import java.util.Scanner;
public class NextLin {
s.close();
}
}
Assignment-6:
Take the day from end user
mon tue wed : print the Discount 5%
thr fri : print the Discount 4%
sat sun : print the Discount 3%
when user entered wrong data give proper error information.
Ans
===
package Guru.Rat.Com;
import java.util.Scanner;
if ((days.startsWith("Mon")) || (days.startsWith("Tue"))
|| (days.startsWith("Wed"))) {
double dis1 = bill * 5 / 100;
double pay = bill - dis1;
System.out.println("Your Discount Amount is " + dis1);
System.out
.println("After Discount your bill Amount is "
+ pay);
}
Arshitha
Assignment:1
import java.util.Scanner;
class Assign
{
public static void main(String[] args)
{
Scanner a=new Scanner(System.in);
System.out.println("Enter Number");
int num=a.nextInt();
if (num%2==0)
{
System.out.println("Your number is even");
}
else
{
System.out.println("Your number is odd");
}
a.close();
}
Assignment:2
import java.util.Scanner;
class Assign1
{
public static void main(String[] args)
{
Scanner b=new Scanner(System.in);
System.out.println("Enter the First Number");
int num1=b.nextInt();
System.out.println("Enter the Second Number");
int num2=b.nextInt();
if(num1>num2)
{
System.out.println("First Number is bigger");
}
else
{
System.out.println("Second Number is bigger");
}
b.close();
}
}
Assignment:3
import java.util.Scanner;
class Assign2
{
public static void main(String[] args)
{
Scanner c=new Scanner(System.in);
System.out.println("Enter the Year");
int year=c.nextInt();
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
{
System.out.println("This is leap year");
}
else
{
System.out.println("This is not a leap year");
}
c.close();
}
}
Assignment:4
import java.util.Scanner;
class Assign3
{
public static void main(String[] args)
{
Scanner c=new Scanner(System.in);
System.out.println("Enter the Username");
String uname=c.next();
System.out.println("Enter the Password");
String pwd=c.next();
if(uname.equals("arshi") && pwd.startsWith("r"))
{
System.out.println("Login Success");
}
else
{
System.out.println("Login failure");
}
c.close();
}
}
Guru:
Positive or Negative with Odd or Even numbers
import java.util.Scanner;
public class EvenOrOdd {
public static void main (String[] args){
Scanner s=new Scanner(System.in);
{
System.out.println("Please Enter your Number :: ");
int num=s.nextInt();
if (num >0)
{
System.out.println("Your Number is Positive number.The number
is :: " + num);
if (num %2==0){
System.out.println("and this is a Even Number");
}
else {
System.out.println("and this is a Odd Number");
}
}
else if (num<0)
{
System.out.println("Your Number is Negative number.The number
is :: " + num);
if (num %2==0){
System.out.println("and this is a Even Number");
}
else {
System.out.println("and this is a Odd Number");
}
}
else
{
System.out.println("The Given Number is Zero");
}
}
s.close();
}
Arshitha:
import java.util.Scanner;
class Assign5
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
}
s.close();
}
}
*******************************************************************************
Usman: Assignment Date: 06th April 2021
Assignment 1: Take the number from end user check it is even or odd?
import java.util.Scanner;
class Evenodd
{
public static void main(String[] args)
{
System.out.println("Enter the number to know EVEN or ODD");
Scanner s = new Scanner(System.in);
int num = s.nextInt();
if ((num%2)==0)
{
System.out.println("Entered number is EVEN");
}
else
{
System.out.println("Entered number is ODD");
}
s.close();
}
}
Assignment 2: Take the two numbers from end user print the bigger number?
import java.util.Scanner;
class BiggerNum
{
public static void main(String[] args)
{
System.out.println("Enter the FIRST number: ");
Scanner s = new Scanner(System.in);
int num1 = s.nextInt();
System.out.println("Enter the SECOND number: ");
int num2 = s.nextInt();
if (num1>num2)
{
System.out.println(num1+" is bigger");
}
else
{
System.out.println(num2+" is bigger");
}
s.close();
}
}
Assignment 3: Take the year from end user check it is leap year or not?
import java.util.Scanner;
class Leapyear
{
public static void main(String[] args)
{ boolean isleap = false;
int year;
System.out.println("Enter any YEAR");
Scanner s = new Scanner(System.in);
year = s.nextInt();
if(year % 4 == 0)
{
if( year % 100 == 0)
{
if ( year % 400 == 0)
isleap = true;
else
isleap = false;
}
else
isleap = true;
}
else {
isleap = false;
}
if(isleap==true)
System.out.println(year + " is a Leap Year.");
else
System.out.println(year + " is not a Leap Year.");
s.close();
}
}
Assignment 4: Take the user name & password from end user. Check the condition
print the the message login Success or fail.
import java.util.Scanner;
class LoginTest
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
String actualUname = "usmanjava";
String actualPass = "ratansir";
String uname;
String pass;
System.out.println("Enter Username");
uname = s.next();
System.out.println("Enter Password");
pass = s.next();
if (actualUname.equals(uname) && actualPass.equals(pass))
System.out.println("Login Successful");
else
System.out.println("Login Failed");
}
s.close();
}
Assignment-5: what is the difference between next() & nextLine() write one
example.
s.next() : to read the String data
s.nextLine() : to read the String data.
next() can read the input only till the space. It can't read two words separated by
a space. Also, next() places the cursor in the same line after reading the input.
nextLine() reads input including space between the words (that is, it reads till
the end of line). Once the input is read, nextLine() positions the cursor in the
next line.
import java.util.Scanner;
class NextLineNext
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
Assignment-6:
Take the day from end user
mon tue wed : print the Discount 5%
thr fri : print the Discount 4%
sat sun : print the Discount 3%
when user entered wrong data give proper error information.
import java.util.Scanner;
class PurchaseDay
{
public static void main(String[] args)
{
String mon = "mon";
String tue = "tue";
String wed = "wed";
String thur = "thur";
String fri = "fri";
String sat = "sat";
String sun = "sun";
System.out.println("Enter the purchase day from the options: Mon, Tue,
Wed, Thur, Fri, Sat, Sun: ");
Scanner s = new Scanner(System.in);
String str = s.next();
if (str.equalsIgnoreCase(mon) || str.equalsIgnoreCase(tue) ||
str.equalsIgnoreCase(wed))
{
System.out.println("Discount is 5%");
}
else if (str.equalsIgnoreCase(thur) || str.equalsIgnoreCase(fri))
{
System.out.println("Discount is 4%");
}
else if (str.equalsIgnoreCase(sat) || str.equalsIgnoreCase(sun))
{
System.out.println("Discount is 3%");
}
else
{
System.out.println("Incorrect Input");
}
s.close();
}
}
*******************************************************************************
Usman: Assignment Date: 12th April 2021
Assignment 1:
-------------
class Test5
{
int a=100;
int b=30;
void add()
{
System.out.println(a+b);
}
void mul()
{
System.out.println(a*b);
}
public static void main(String[] args)
{
Test5 d = new Test5();
d.add();
t.mul();
}
Assignment 2:
-------------
class Demo
{
int a=100;
int b=30;
}
class Test5
{
int a=100;
int b=30;
void add()
{
Demo d =new Demo();
System.out.println(a+b);
}
void mul()
{
Demo d1 =new Demo();
System.out.println(a*b);
}
public static void main(String[] args)
{
Test5 t = new Test5();
t.add();
t.mul();
}
}
*******************************************************************************
Usman: Assignment Date: 13th April 2021
Assignment-1:
class Test
{ declare 2-static var
static void add()
{ print the addition
}
static void mul()
{ print the multiplication
}
public static void main(String[] args)
{ call the add
call the mul
}
}
ANSWER:
class Static1
{
static int a = 10;
static int b = 20;
public static void main(String[] args)
{
Static1.add();
Static1.mul();
}
/* OUTPUT
Addition is: 30
Multiplication is: 200
*/
=====================================================================
Assignment-2:
class Test
{ declare 2-instance var
static void add()
{ print the addition
}
static void mul()
{ print the multiplication
}
public static void main(String[] args)
{ call the add
call the mul
}
}
ANSWER:
class Static2
{
int a = 10;
int b = 20;
public static void main(String[] args)
{
Static2 st = new Static2();
st.add();
st.mul();
}
/* OUTPUT:
Addition is: 30
Multiplication is: 200
*/
*/
*******************************************************************************
Usman: Assignment Date: 19th April 2021
import java.util.Scanner;
class Voter
{
void voteRegister(String name, String location, int mobile, int age, int
sscRollNo)
{
else
{
System.out.println("Not eligible for voting");
}
else
{
System.out.println("Not eligible, please try after sometime");
}
}
}
*******************************************************************************
Arshitha:
Assignment:1
class Services
{
void voteRegister(String name,int mobile,int age,int sscRollNo,String
location)
{
if(age>18 && location.equalsIgnoreCase("Hyd")){
System.out.println("You are eligible for voting"+" "+"Your Voter
Id num:"+" "+mobile+sscRollNo+age);
}
else if((age<=18 && location.equalsIgnoreCase("Hyd")) || (age>=18 &&
location.equalsIgnoreCase("Hyd")));
{
System.out.println("Not eligible for voting");
}
}
}
}
siva kumar:-
==============
constructor assignment:- (22/04/2021)
========================
class Customer
{
String cname;
int pid;
String pname;
double pcost;
int quantity;
public static final int gst=10;
public static final String brand="honeywell";
public static final int discount=5;
Customer(String cname,int pid,String pname,double pcost,int quantity)
{
this.cname=cname;
this.pid=pid;
this.pname=pname;
this.pcost=pcost;
this.quantity=quantity;
}
double totalBill()
{
double bill;
bill=(pcost*quantity+Customer.gst)*95/100;
return bill;
}
System.out.println("***************************************************************
************************************");
Customer c1=new Customer("kumar",4321,"shirt",1000.45,5);
System.out.println("cname:"+c.cname+" "+"pid:"+c.pid+" "+"pname:"+c.pname+"
"+"pcost:"+c.pcost+" "+"quantity:"+c.quantity+
" "+"gst:"+Customer.gst+" "+"brand:"+Customer.brand+"
"+"discount:"+Customer.discount);
double total2=c1.totalBill();
System.out.println("your bill is:"+total2);
}
}
o/p:-
======
D:\java by siva>java Customer
cname:siva pid:1234 pname:book pcost:500.45 quantity:2 gst:10 brand:honeywell
discount:5
your bill is:960.355
***********************************************************************************
****************
cname:siva pid:1234 pname:book pcost:500.45 quantity:2 gst:10 brand:honeywell
discount:5
your bill is:4761.6375
assignment:-
================
ex-3: Application contains three packages.
com.tcs.data.instancedata;
class Test
{ 1-instance var
1-instance methods
}
com.tcs.data.staticdata;
class Demo
{ 1-static var
1-static method
}
com.tcs.data.client;
class TestClient
{ public static void main(String[] args)
{ Acccess the instance data
Access the static data.
}
}
siva kumar:-(26-04-2021):
=========================
package assignment-1:-
======================
package com.tcs.data.instancedata;
public class Test
{
int a=10;
int b=20;
package com.tcs.data.staticdata;
package com.tcs.data.main;
import com.tcs.data.instancedata.Test;
import com.tcs.data.staticdata.Demo;
}
}
o/p:-
======
D:\java by siva>javac -d . Test.java
}
}
27-07-2021:-
============
sivakumar
==*****==
class Test
{
public static void main(String[] args){
int[] a={10,20,30,40,50};
int sum=0;
for (int i=0;i<a.length ;i++ )
{
sum=sum+a[i];
}
System.out.println("the sum of array is:"+sum);
int min=a[0];
int max=a[0];
for (int i=0;i<a.length ;i++ )
{
if(a[i]<min)
min=a[i];
if(a[i]>max){
max=a[i];
}
}
System.out.println("minimum value in the array is:"+min);
System.out.println("maximum value in the array is:"+max);
}
}