RHS -> Allan->SWC -> Tests -> Test01

Test 01

  Question 1.  
   

Look at the following two lines of code:

double f = 4.35;
System.out.println(100 * f);

Explain in few words why the second line is actually printing "434.99999999999994" and not "435" as expected.
 
   
Write your answer here:

 

 

 

 
  Question 2.  
   

Which of the following 4 statements are correct Java syntax?

    1. int a = 3.0;
    2. double b = 5;
    3. int c = (double) 3.0;
    4. int d = (int) 3.0;
 
   
Write your answer here:

 

 

 
  Question 3.  
   

Which of the following possibilities declares an integer constant with the value 5 in a Java program?
Please note that there can be more than one correct possibility!

    1. int CONST = 5;
    2. int static Const = 5;
    3. int void final CONST = 5;
    4. int final CONST = 5;
    5. int final CONST;
      CONST = 5;
    6. int static final const = 5;
    7. int static final CONST = 5;
 
   
Write your answer here:

 

 

 
  Question 4.  
   

Find the result of the following statements from a Java program:

    1. 15 / 4
    2. 15 % 4
    3. 5 + 4 / 2
    4. 4 / 2.0
    5. (5 + 4) / 2.0
    6. Math.round(3.6)
 
   


Write your answer here:

        1. _________

        2. _________

        3. _________

        4. _________

        5. _________

        6. _________

 

 
  Question 5.  
   

Assume that the following statements has been executed in a Java program:
      String n = "Hello, is there anybody in there?";
      String x = "C:\\Folder";

Write the results from the following statements from that program:

  1. name = n.substring(1, 10);
  2. name = n.substring(8);
  3. name = x.substring(1, 5);
  4. name = x.charAt(2) + x.charAt(3) + x.charAt(0);
 
   
Write your answer here:

 

 

 

 


Maintained by: Allan Helboe
Updated: 28 November, 2007 15:57