PRACTICAL QUESTIONS Android Studio
PRACTICAL QUESTIONS Android Studio
IN INFORMATION TECHNOLOGY
PRACTICAL 2 (WEEK – 2)
1. Write the following operation in the main method to print their output:
-3 + 5 * 8
(105+7) % 4
34 + -5 * 8 / 6
7 + 15 / 2 * 6 - 7 % 3
ANSWER#1:
public class practicalNum1 {
public static void main(String args[]){
System.out.println("-3 + 5 * 8");
System.out.println("(105+7) % 4 ");
System.out.println("34 + -5 * 8 / 6 ");
System.out.println("7 + 15 / 2 * 6 - 7 % 3");
}
}
Result:
2. Write Java codes to produce the following output:
ANSWER#2:
Result:
3. By using for loop, write the codes to produce the following output:
int VarX = 3;
int Result = 1;
Result:
4. Modify the codes in Q3 to get the sum of all the output (3, 6, …, 30).
int VarX = 3;
int Result = 1; //Use to store the result, try to change to 0 and
see the result change
int sum = 0;
System.out.println("Input Integer: " + VarX);
for(int i = 1; i<=10;i++){
System.out.print(VarX + " x " + i + " = ");
Result = i * VarX;
sum += Result;
System.out.println(Result);
}
System.out.println("The total sum of all results: " + sum);
}
}
result;
5. By using switch statement, display the colors according to the RGB input.
Sample output:
Result:
6. Create a Java method to accept student’s mark (0 – 100 marks) and return grade to the main
method. Main method will display the grade that the student obtained.
Result: