JAVA-------SEM-1 Assignment 2
Q_01
Scanner input = new Scanner(System.in);
System.out.print("Enter a value in celsius: ");
double cel = input.nextDouble();
double far = 9.0/5*cel + 32;
System.out.println(cel + " degree in celsius is " + far + " degree in farhenheit.");
Q_02
Scanner input = new Scanner(System.in);
System.out.print("Enter radius: ");
double rad = input.nextDouble();
System.out.print("Enter length: ");
double len = input.nextDouble();
double area = rad*rad*Math.PI;
double volume = area * len;
System.out.println("area is: " + area);
System.out.println("volume is: " + volume);
Q_03
Scanner x = new Scanner(System.in);
System.out.print("Enter a value for feet: ");
double feet = x.nextDouble();
double meter = feet*0.305;
System.out.println(feet + " feet is " + meter + " meters.");
Q_04
Scanner x = new Scanner(System.in);
System.out.print("Enter a integer no. between 0 and 1000: ");
int a = x.nextInt();
int b = ((a%10)+((a/10)%10) + ((a/100)%10) + (a/1000));
System.out.println("The sum of the digits is: " + b);
Q_05
double v0 , v1 , t , avg;
Scanner x = new Scanner(System.in);
System.out.print("Enter the value for v0: ");
v0 = x.nextDouble();
System.out.print("Enter the value for v1: ");
v1 = x.nextDouble();
System.out.print("Enter the value for t: ");
t = x.nextDouble();
avg = (v1 - v0)/t;
System.out.println("The average acceleration is " + avg);
Q_06
Scanner in = new Scanner(System.in);
System.out.print("Enter weight in pounds: ");
double pound = in.nextDouble();
System.out.print("Enter height in inches: ");
double inch = in.nextDouble();
double kgs , meter , BMI;
kgs = pound*0.45359237;
meter = inch*0.0254;
BMI = kgs/(Math.pow(meter, 2));
System.out.println("Your BMI is: " + BMI);
Q_07
Scanner in = new Scanner(System.in);
System.out.print("Enter the side of the hexagon: ");
double side = in.nextDouble();
double area = (3*Math.sqrt(3)/2)*Math.pow(side, 2);
System.out.println("The area of the hexagon is: " + area);
Q_08
System.out.println("a b pow(a,b)");
double a , b;
a = 1;
b = a+1;
System.out.println((int)a+" "+(int)b+" "+(int)Math.pow(a, b));
a = ++a;
b = ++b;
System.out.println((int)a+" "+(int)b+" "+(int)Math.pow(a, b));
a = ++a;
b = ++b;
System.out.println((int)a+" "+(int)b+" "+(int)Math.pow(a, b));
a = ++a;
b = ++b;
System.out.println((int)a+" "+(int)b+" "+(int)Math.pow(a, b));
a = ++a;
b = ++b;
System.out.println((int)a+" "+(int)b+" "+(int)Math.pow(a, b));
Q_09
Scanner x = new Scanner(System.in);
double x1 , x2 , y1 , y2 , dist;
System.out.print("A(x1 , y1)= ");
x1 = x.nextDouble();
x2 = x.nextDouble();
System.out.print("B(x2 , y2)= ");
y1 = x.nextDouble();
y2 = x.nextDouble();
dist = Math.pow((Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), 0.5);
System.out.println("The distance between A and B is: " + dist);
Q_10
Scanner in = new Scanner(System.in);
double x1 , x2 , x3 , y1 , y2 , y3 , s1 , s2 , s3 , s , area;
System.out.print("A(x1 , y1)= ");
x1 = in.nextDouble();
y1 = in.nextDouble();
System.out.print("B(x2 , y2)= ");
x2 = in.nextDouble();
y2 = in.nextDouble();
System.out.print("C(x3 , y3)= ");
x3 = in.nextDouble();
y3 = in.nextDouble();
s1 = Math.pow((Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), 0.5);
s2 = Math.pow((Math.pow(x3 - x1, 2) + Math.pow(y3 - y1, 2)), 0.5);
s3 = Math.pow((Math.pow(x3 - x2, 2) + Math.pow(y3 - y2, 2)), 0.5);
s = (s1 + s2 + s3)/2;
area = Math.pow(s*(s - s1)(s - s2)(s - s3), 0.5);
System.out.println("Area of the triangle ABC is: " + area);
Q_11
Scanner x = new Scanner(System.in);
double amount , annual , time , monthly , investment;
System.out.print("Enter the amount: ");
amount = x.nextDouble();
System.out.print("Enter the annual interest rate: ");
annual = x.nextDouble();
System.out.print("Enter no. of years: ");
time = x.nextDouble();
monthly = annual/1200;
investment = amount*Math.pow((1 + monthly) , time*12);
System.out.println("Accumulated value is $" + investment);
Q_12
Scanner x = new Scanner(System.in);
int total , gross , dozen , left;
System.out.print("Enter the no. of eggs: ");
total = x.nextInt();
gross = total/144;
dozen = total%144/12;
left = total%144%12;
System.out.println("You have " + gross + " gross " + dozen + " dozen and " + left + " eggs.");
Q_13
Scanner x = new Scanner(System.in);
int minutes , days , years;
System.out.print("Enter minutes: ");
minutes = x.nextInt();
years = minutes/(60*24*365);
days = minutes%(60*24*365)/(60*24);
System.out.println("It is " + years + " years and " + days + " days.");
Q_14
int a , b;
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
System.out.println(((a%b)==0)||((b%a)==0));
Q_15
int a , b , c;
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
System.out.println("First no.: " + a);
System.out.println("Second no.: " + b);
c = (a + (int)(Math.random()*(b-a+1)));
System.out.print("Random number : " + c);
Q_16
int a , b;
a = (1 + (int)(Math.random()*(6)));
b = (1 + (int)(Math.random()*6));
System.out.println(a + b);
Q_17
int a,b,c;
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
c = Integer.parseInt(args[2]);
System.out.println((a >= (b+c))||(b >= (a+c))||(c >= (b+a)));
Q_18
double x , y , z;
x = Double.parseDouble(args[0]);
y = Double.parseDouble(args[1]);
z = Double.parseDouble(args[2]);
System.out.println(((x>y)&&(y>z))||((z>y)&&(y>x)));
Q_19
double BS , DA , HRA , gross;
BS = Double.parseDouble(args[0]);
DA = BS*(0.4);
HRA = BS*(0.2);
gross = BS + DA + HRA;
System.out.println("Enter your salary: " + BS);
System.out.println("Your DA: " + DA);
System.out.println("Your HRA: " + HRA);
System.out.println("Your Gross salary: " + gross);
Q_20
int d , m;
d = Integer.parseInt(args[0]);
m = Integer.parseInt(args[1]);
System.out.println(((m==3)&&(d>19&&d<32))||((m==4)&&(d>0&&d<31))||((m==5)&&(d>0&&d<32))||((m==6)&&(d>0&&d<21)));
Q_21
double t;
t = Double.parseDouble(args[0]);
System.out.println(Math.sin(t*2) + Math.cos(t*3));
Q_22
int p , r , t;
p = Integer.parseInt(args[0]);
r = Integer.parseInt(args[1]);
t = Integer.parseInt(args[2]);
System.out.println(p*Math.exp(r*t));
Q_23
int a , b , c , min , max;
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
c = Integer.parseInt(args[2]);
max = Math.max(Math.max(a , b) , c);
min = Math.min(Math.min(a , b) , c);
System.out.println(min + "<" + (a+b+c-(min+max)) + "<" + max);
Q_24
double a , b , c , d , e , max , min , avg;
a = Math.random();
b = Math.random();
c = Math.random();
d = Math.random();
e = Math.random();
max = Math.max(Math.max(Math.max(Math.max(a , b) , c) , d) , e);
min = Math.min(Math.min(Math.min(Math.min(a , b) , c) , d) , e);
avg = (a + b + c + d + e)/5;
System.out.println("First number: " + a);
System.out.println("Second number: " + b);
System.out.println("Third number: " + c);
System.out.println("Fourth number: " + d);
System.out.println("Fifth number: " + e);
System.out.println("Maximum: " + max);
System.out.println("Minimum: " + min);
System.out.println("Average: " + avg);
XXXX-------THE END--------XXXX
Comments
Post a Comment