0% found this document useful (0 votes)
125 views5 pages

PPJ Test Example ENG v1.2

Uploaded by

Jonathan Hook
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views5 pages

PPJ Test Example ENG v1.2

Uploaded by

Jonathan Hook
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

0 0 0 0 0

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

PPJ Example Test


1432vbsuildf12351

In this test, you can earn 10 points.

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.

 In Java, all variables must be initialized before they are used.


 The ternary operator can be replaced with a do-while statement.
 The switch statement can initialize a variable.
 The expression b = a++; can be replaced with b = a; a = a + 1;
 In Java, the == operator can be used to compare two strings (String objects) based on their
content.
 A variable declared inside a while loop is accessible after the loop has finished.
 Java is a case-sensitive language.
 Files after compilation have the extension .java
Task2
Present only the program's output. A correct output earns 0.5 points. All codes compile correctly and
are placed inside the main method.

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 [] tab = new int[3];


for (int i = 0; i < tab.length-1; i++) {
tab[i]++;
tab[i+1] = tab[i];
}
System.out.println(Arrays.toString(tab));

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy