Vous êtes sur la page 1sur 3

Assignment 1

Make it sure to do it by yourself. And it's your choice to give values to variables
Try to implement as much as you can. If you cann't implement leave it. We will discuss
it in class

Questions 1:Change the following program to use compound/Dynamic assignments:


class ArithmeticDemo {
public static void main (String[] args){
int result = 1 + 2; // result is now 3
System.out.println(result);
result = result - 1; // result is now 2
System.out.println(result);
result = result * 2; // result is now 4
System.out.println(result);
result = result / 2; // result is now 2
System.out.println(result);
result = result + 8; // result is now 10
result = result % 7; // result is now 3
System.out.println(result);
}

Question 2:In the following program, explain why the value "6" is printed twice in a row:
class PrePostDemo {
public static void main(String[]
int i = 3;
i++;
System.out.println(i);
//
++i;
System.out.println(i);
//
System.out.println(++i); //
System.out.println(i++); //
System.out.println(i);
//
}
}

args){
"4"
"5"
"6"
"6"
"7"

Question 3:Implement the following formulas

(a/b) +( c/d) = ((a*d)+(b*c))/(b*d)

(a/b)-(c/d) = ((a*d)-(b*c))/(b*d)

(a/b)*(c/d) = (a*c)/(b*d)

(a/b)/(c/d) = (a*d)/(b*c)

Write separate program for every formula.


Remember Both sides of formula must be in same program. Display the result of both side.

Question 4:Implement the following formulas (Only Two formulas will be in same application )
Area of Triangle (b h)/2
Area of (b1 + b2) h/2 // you have detect the precedence by itself
Volume of a sphere: (4/3) pi r3

hint: you can write r3 as r*r*r

Volume of a triangular prism: (1/2 base height) height


Volume of a cylinder:

pi r2 Height

hint: r2 = r*r

Question 5:Find Slope of Line Formula for slope is


m= y2-y/x2-x1

// you have detect the precedence by itself

Question 6:Point-Slope Equation of a line


y-y1 = m(x-x1)
Calculate both sides and print the result

Question 7:Calculate Interest Formula for interest is

where pi = 22/7

I = ART

where (I= Interest, A= Amount, R = rate, T= Time)

Question 8:
Find SURFACE AREA (SA) of
Cude Formula 6*s*s
Cylinder

Formula 2*pi*r*h

Vous aimerez peut-être aussi