Sie sind auf Seite 1von 4

Day 2 Activities

Activity 1:
Predict the truth table results
A B A && B A || B
TRUE TRUE True True
TRUE FALSE False True
FALSE FALSE False False

Activity 2:
Consider the following Java code. The code is expected to give the output as 100. But the code
has some error. Request you to fix the error and make sure that the code will give the expected
output.
public class Test {
public static void main (String args []) {
int x;
System.out.println(x);
}
}
A:
public class Test {
public static void main (String[] args) {
int x=100;
System.out.println(x);
}
}

Activity 3:
Identify the Java Keywords from below table.
F O R O H C T I W S
I M P L E M E N T S
W D N A T I V E U Q
H O A R D S S A L C
I W H I L E I N Y T
L A E N P O H P K O
E P L T R E T U R N
V O L A T I L E Z X
A: int, while, for, or,

Activity 4:
Considering the below code, predict the output:
public class MainClass{
public static void main(String[] args){
for (int i = 0; i < 100; i++){
System.out.println(i);
if(i == 50){
break;
}
}
}
}

A: Output:
0,1,2,3,4,5,6,7,8,9,10,11,12,13,…,48,49,50

Activity 5:
Consider the following program, and predict the output:
Below are the input data:

 day =2
 day = 3
 day = 9
public class MainClass{
public static void main(String[] args){
System.out.println("Enter Day :");

int day; // Refer the input data

switch (day){
case 1 : System.out.println("SUNDAY");
break;
case 2 : System.out.println("MONDAY");
break;
case 3 : System.out.println("TUESDAY");

case 4 : System.out.println("WEDNESDAY");
case 5 : System.out.println("THURSDAY");

case 6 : System.out.println("FRIDAY");

case 7 : System.out.println("SATURDAY");

default: System.out.println("Invalid");
break;
}
}
}

Activity 6:
Consider the following code and predict the output:
public class MainClass{
public static void main(String[] args){
for (int i = 0; i <= 100; i++){
if(i % 5 != 0){
continue;
}
System.out.println(i);
}
}
}

Activity 7:
What will be the output of the following Java code?
public class Test{
public static void main (String args []){
int x = 10;
do {
System.out.print("value of x: " + x);
System.out.print("\n");
} while (x > 20);
}
}

Activity 8:
Consider the following code snippet and predict the output:
public class MainClass{
public static void main(String[] args){
int i = 10;
while (i <= 100){
System.out.println(i);
i = i + 10;
}
}
}

Activity 9:
Consider the following code and predict the outputs:
public class MainClass {
public static void main(String[] args) {

int a[] = {3, 4, 7, 8};

System.out.println(a[0]);
System.out.println(a[3]);
System.out.println(a[4]);

}
}

Das könnte Ihnen auch gefallen