PPJ Test Example ENG v1.2
PPJ Test Example ENG v1.2
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
6 6 6 6 6
7 7 7 7 7
8 8 8 8 8
9 9 9 9 9
Task1
Evaluate each sentence as 'T' if it is true or 'F' if it is false by entering the value in the field .
A correct answer earns you 0.5 points, while an incorrect answer deducts 0.5 points. Not answering
does not affect the point total.
int a = 5, b = 10;
int c = --a + b++;
System.out.println("a =" + a + " b =" + b + " c =" + c);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == 1)
break;
System.out.println("i & j = " + i + " & " + j);
}
}
int a = 5;
int b = 0x11;
int c = 010;
System.out.println((a + b) ^ c);
int sum = 0;
for (int i = 1; i <= 5; ++ i ) {
if ( i % 3 == 0)
continue ;
System.out.print ( sum + " ") ;
sum += i ;
}
System.out.println ( sum ) ;
String s = "hello-in-hell";
for (int i = 4; i < s.length(); i+=3) {
System.out.print(s.charAt(i) + " ");
}
int k = 16;
if (k % 4 == 0 && k / 3 == 5)
System.out.println("Are you sure?");
System.out.println((int)Math.random());
String obi = "Hello there";
String grievous = "";
switch (obi) {
case "Hello there":
grievous += "General";
case "obi":
grievous += " Kenobi";
case "Wan":
grievous += " You";
case "General":
grievous += " are";
case "Sith":
grievous += " a";
case "meme":
grievous += " bold";
default :
grievous += " one";
}
System.out.println(grievous);
Task3
For 1 point. Write Java code that will represent the same logic and behaviour shown in flowchart
For 1 point. Write a program that generates a pyramid of integers. The program should work for any
integer value n, which determines the height of the pyramid. The task must be solved without using
arrays, collections, or strings.
Example n = 5:
1
22
333
4444
55555
Examplen = 3:
1
22
333