The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer toner, and save money. If you prefer to work my exams from printed pages, then you can save a tree, save your printer toner, and save money if you buy my new book instead of attempting to print the pages of my web site.
Today, you can find my book on the retail web site of the company that prints it and distributes it.
class SRC102 {
public static void main (String[] args) {
int i1 = Math.round(0.5f);
int i2 = Math.round(1.5d);
System.out.print(i1 + "," + i2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,1 |
| b. | Prints: 0,2 |
| c. | Prints: 1,1 |
| d. | Prints: 1,2 |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class SRC103 {
public static void main (String[] args) {
int i1 = Math.round(0.5f);
int i2 = Math.round(1.5f);
System.out.print(i1 + "," + i2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,1 |
| b. | Prints: 0,2 |
| c. | Prints: 1,1 |
| d. | Prints: 1,2 |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class SRC104 {
public static void main (String[] args) {
System.out.print(Math.round(Float.NaN));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: NaN |
| b. | Prints: 0.0 |
| c. | Prints: 0 |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class SRC105 {
public static void main(String[] args) {
double d1 = Math.ceil(0.5);
double d2 = Math.ceil(1.5);
System.out.print(d1 + "," + d2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0.0,1.0 |
| b. | Prints: 0.0,2.0 |
| c. | Prints: 1.0,1.0 |
| d. | Prints: 1.0,2.0 |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class SRC106 {
public static void main(String[] args) {
double d1 = Math.floor(0.5);
double d2 = Math.floor(1.5);
System.out.print(d1 + "," + d2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0.0,1.0 |
| b. | Prints: 0.0,2.0 |
| c. | Prints: 1.0,1.0 |
| d. | Prints: 1.0,2.0 |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class SRC107 {
public static void main (String[] args) {
int a = -1; long b = -2;
float c = -3.0f; double d = -4.0;
a = Math.abs(a); b = Math.abs(b);
c = Math.abs(c); d = Math.abs(d);
System.out.print(a+b+c+d);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 10.0 |
| b. | Compile-time error |
| c. | Run-time error |
| d. | None of the above |
class SRC109 {
public static void main (String[] args) {
short x3 = 0; short x4 = 1;
short b1 = Math.min(x3,x4); // 1
int c1 = Math.min(0,1); // 2
long d1 = Math.min(0L,+1L); // 3
System.out.print(b1+","+c1+","+d1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0,0 |
| b. | Compile-time error at 1 |
| c. | Compile-time error at 2 |
| d. | Compile-time error at 3 |
| e. | Run-time error |
| f. | None of the above |
class SRC110 {
public static void main (String[] args) {
byte x1 = 0; byte x2 = 1;
byte a1 = Math.min(x1,x2); // 1
int c1 = Math.min(0,1); // 2
long d1 = Math.min(0L,+1L); // 3
System.out.print(a1+","+c1+","+d1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0,0 |
| b. | Compile-time error at 1 |
| c. | Compile-time error at 2 |
| d. | Compile-time error at 3 |
| e. | Run-time error |
| f. | None of the above |
class SRC111 {
static String m(byte i) {return "byte";}
static String m(short i) {return "short";}
static String m(char i) {return "char";}
static String m(int i) {return "int";}
static String m(double i) {return "double";}
public static void main (String[] args) {
byte b = 0; short s = 0; char c = 0;
System.out.print(m(Math.min(b,b))+",");
System.out.print(m(Math.min(s,s))+",");
System.out.print(m(Math.min(c,c)));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: byte,byte,byte |
| b. | Prints: short,short,short |
| c. | Prints: int,int,int |
| d. | Prints: byte,short,int |
| e. | Prints: short,short,int |
| f. | Prints: byte,short,char |
| g. | Compile-time error |
| h. | Run-time error |
| i. | None of the above |
class SRC112 {
static String m(byte i) {return "byte";}
static String m(int i) {return "int";}
static String m(long i) {return "long";}
static String m(double i) {return "double";}
public static void main (String[] args) {
byte b = 0;
System.out.print(m(Math.min(b,b))+",");
System.out.print(m(Math.min(b,1))+",");
System.out.print(m(Math.min(b,1L)));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: byte,byte,byte |
| b. | Prints: byte,int,long |
| c. | Prints: int,int,int |
| d. | Prints: int,int,long |
| e. | Prints: long,long,long |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class SRC113 {
static String m(byte i) {return "byte";}
static String m(short i) {return "short";}
static String m(char i) {return "char";}
static String m(int i) {return "int";}
static String m(long i) {return "long";}
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
byte b = 0; short s = 0; char c = 0;
System.out.print(m(Math.min(b,1L))+",");
System.out.print(m(Math.min(s,1.0f))+",");
System.out.print(m(Math.min(c,1.0)));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: int,int,int |
| b. | Prints: byte,short,char |
| c. | Prints: long,float,double |
| d. | Prints: double,double,double |
| e. | Prints: long,long,long |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class SRC114 {
static String m(int i) {return "int";}
static String m(long i) {return "long";}
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
System.out.print(m(Math.random()));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: int |
| b. | Prints: long |
| c. | Prints: float |
| d. | Prints: double |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class SRC115 {
static String m(int i) {return "int";}
static String m(long i) {return "long";}
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
long seed = 1L;
System.out.print(m(Math.random(seed)));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: int |
| b. | Prints: long |
| c. | Prints: float |
| d. | Prints: double |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class SRC116 {
static String m(int i) {return "int";}
static String m(long i) {return "long";}
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
System.out.print(m(Math.sin(0.0f))+",");
System.out.print(m(Math.cos(0.0f))+",");
System.out.print(m(Math.tan(0.0f)));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: int,int,int |
| b. | Prints: long,long,long |
| c. | Prints: float,float,float |
| d. | Prints: double,double,double |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class SRC117 {
public static void main (String[] args) {
double d1 = Math.random();
boolean b1 = (d1 < 0.0), b2 = (d1 <= 0.0), b3 = (d1 == 0.0);
boolean b4 = (d1 >= 0.0), b5 = (d1 < 1.0), b6 = (d1 <= 1.0);
boolean b7 = (d1 == 1.0), b8 = (d1 >= 1.0), b9 = (d1 > 1.0);
}}
Which of the boolean variables will never be initialized to the value true?
| a. | b1 |
| b. | b2 |
| c. | b3 |
| d. | b4 |
| e. | b5 |
| f. | b6 |
| g. | b7 |
| h. | b8 |
| i. | b9 |
Which method of the java.lang.Math class is not static?
| a. | abs |
| b. | ceil |
| c. | floor |
| d. | max |
| e. | min |
| f. | random |
| g. | round |
| h. | sin |
| i. | cos |
| j. | tan |
| k. | sqrt |
| l. | None of the above |
Some of the following method names are overloaded and some are not. Which of the following method names are overloaded such that for each of the following four primitive types int, long, float and double there is at least one corresponding method that returns that type?
| a. | abs |
| b. | ceil |
| c. | floor |
| d. | max |
| e. | min |
| f. | random |
| g. | round |
| h. | sin |
| i. | cos |
| j. | tan |
| k. | sqrt |
class SRC118 {
static String m1(int i) {return "I";}
static String m1(long i) {return "L";}
static String m1(float i) {return "F";}
static String m1(double i) {return "D";}
public static void main (String[] args) {
System.out.print(m1(Math.abs(1.0)) + m1(Math.ceil(1.0f)));
System.out.print(m1(Math.max(1.0,1.0)) + m1(Math.round(1.0)));
System.out.print(m1(Math.sin(1.0)) + m1(Math.sqrt(1.0)));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: DDDDDD |
| b. | Prints: LLLLLL |
| c. | Prints: DLLLDD |
| d. | Prints: DIDLDD |
| e. | Prints: DLDLDD |
| f. | Prints: DDDLDD |
| g. | Prints: DIDIDD |
| h. | None of the above |
class SRC119 {
static String m1(int i) {return "I";}
static String m1(long i) {return "L";}
static String m1(float i) {return "F";}
static String m1(double i) {return "D";}
public static void main (String[] args) {
System.out.print(m1(Math.floor(1.0f)) + m1(Math.floor(1.0d)));
System.out.print(m1(Math.ceil(1.0f)) + m1(Math.ceil(1.0d)));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: IIII |
| b. | Prints: ILIL |
| c. | Prints: LLLL |
| d. | Prints: FDFD |
| e. | Prints: DDDD |
| f. | None of the above |