WorksheetsComputer Science Unit 3 Test
Total questions: 15
Worksheet time: 30mins
What is the difference between System.out.print and System.out.println
.print will give an error
.println will give an error
.println will start a new line after your message
print will start a new line
int x = 5;
int y = 4;
double z = x/y; What will z be set to?
1.0
1
1.25
Error
double a = 5;
double b = 3;
int c = a/b; What will c be set to?
Error
1.66666...
1
1.0
int a = 9;
double b = 10;
double c = a/b; What will c be set to?
0.9
0
1.1111...
Error
int x = 10;
int y = 55;
System.out.print("a" + x + y); //What will this line output?
axy
a1055
a65
65
int x = 10;
int y = 55;
System.out.print("a" + (x + y)); //What will this line output?
axy
a1055
a65
65
int a = 3;
int b = 4;
double c = Math.pow(a, b); What will c be set to?
81
64
12
7
int a = 49;
double g = Math.sqrt(a);
What will g be set to?
7
9
Error
e49
int x = 7;
int y = 5;
System.out.print(x + y + "z"); //What will this line output?
xyz
12z
75z
z75
double a = 6.0;
int b = (int)a/4
What will b be set to?
1.5
1
0.6666...
Error
int a = 4;
int b = 3;
double c = (double)b/a
0.75
0
1
Error
int page = (int)(Math.random() * 500) +1
What are possible values of page?
Between 1 and 500 (inclusive)
Between 0 and 1 (excluding 1)
Between 0 and 500 (inclusive)
Any number
Which of these adds 5 to the value of x?
x =+ 5
x = 5
x += 5
x * 5
What does b-- do?
Makes b negative
Subtracts 1 from the value of b
Nothing
Subtracts 2 from the value of b
What does
x %= 4;
do?
divides x by 4
sets x to the remainder when x is divided by 4
gives an error
sets x to 4%
