You are on page 1of 4

Exercise 1

Find the value of each of the expressions in JAVA

1. 9 – 5 -3 Answer is 1
2. 2.0 + 3.0 / 5.0 Answer is 2.6
3. 2+3/5 Answer is 2
4. 5/2+3 Answer is 5
5. 2 + Math.pow(3,2) Answer is 11.0
6. Math.pow((2+3), 2) Answer is 25.0
7. 12.0 / 1.0 * 3.0 Answer is 36.0
8. (2 + 3 *4) / (8 -2 + 1) Answer is 2
9. (2 + 3*3) / (8-2+1) Answer is 1
10. (2 .0 + 3*3) / (8-2+1) Answer is 1.57
11. Math.pow(-3.0,2) Answer is 9.0
12. Math.sqrt(6.0+3.0) 3.0
13. Math.exp(3.0-2.0-1.0) 1.0
14. Math.floor(5.0+4.0/3.0) 6.0

Exercise 2

1. Write type statement to declare Temperature, Pressure and Volume to be real variables.

double temperature, pressure, volume;

2. Write type statement to declare Code and Count to be integer variables.

int code, count;

3. Write type statement to declare Axis character variable

char axis;
Exercise 3

Assume the following declarations have been made:

int inteight=8, intfive = 5, jobid;


double two=2.0, three=3.0, four = 4.0, xvalue;

find the value assigned to the given variable

1. xvalue = Math.pow((three+two/four),2); 12.25


2. xvalue = inteight / intfive + 5.1; 6.1
3. jobid = (int)(inteight / intfive + 5.1); 6
4. inteight = inteight + 2; 10
5. xvalue = Math.sqrt(three*three + four*four); 5.0
6. inteight = (int) Math.abs(three – 4.5); 1
7. xvalue = Math.sqrt(Math.abs(two – three)); 1.0
8. jobid = (int) Math.max(Math.floor(four/4), 1.5); 1

Exercise 4

Write a JAVA assignment statement that calculates the given expression and assigns the results to the
specified variable.

1. Rate times Time to Distance


𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑 = 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 ∗ 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡;
2. √𝐴𝐴2 + 𝐵𝐵2 to C
𝑐𝑐 = 𝑀𝑀𝑀𝑀𝑀𝑀ℎ. 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠(𝑎𝑎 ∗ 𝑎𝑎 + 𝑏𝑏 ∗ 𝑏𝑏);
3. Increment count by 1
𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 = 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 + 1;
4. 𝐴𝐴2 + 𝐵𝐵2 − 2𝐴𝐴𝐴𝐴 cos 𝜃𝜃 to X
𝑥𝑥 = 𝑎𝑎 ∗ 𝑎𝑎 + 𝑏𝑏 ∗ 𝑏𝑏 − 2 ∗ 𝑎𝑎 ∗ 𝑏𝑏 ∗ 𝑀𝑀𝑀𝑀𝑀𝑀ℎ. cos(𝑡𝑡ℎ𝑒𝑒𝑒𝑒𝑒𝑒) ;
1
5. 1 1 1 to Resistance
+ +
R1 R2 R3
resistance=1/(1/r1+1/r2+1/r3);
2𝑣𝑣 2 sin 𝛼𝛼 cos 𝛼𝛼
6. to Range
𝐺𝐺
Range = (2*v*v*Math.sin(alpha)*Math.cos(alpha)) / g;
Exercise 5

What output will the following program produce?

import java.util.Scanner;

public class NewClass {

public static void main (String args[])

Scanner input = new Scanner( System.in );

int i, j;

double x,y;

x= 37;

i=(int)(x/5);

System.out.printf("%.2f \t %d \n",x,i);

x=input.nextDouble();

i=input.nextInt();

System.out.printf("x= %.2f \t i= %d\n",x,i);

y=input.nextDouble();

j=input.nextInt();

System.out.printf("y= %.2f\n",y);

System.out.printf("j= %d\n",j);

Assume that the data values are entered as follows:

1.74

29

4.23
Thank you for evaluating AnyBizSoft PDF Password Remover.

With the trial version, only the first 3 pages of each file can be exported.

To get all the pages exported, you need to purchase the software from

http://www.anypdftools.com/buy/buy-pdf-password-remover.html

You might also like