Professional Documents
Culture Documents
Import Java
Import Java
//1. By using do while loop, write Java program to prompt the user to choose the correct answer from a
list of answer choices of a question (minimum 10 sets of questions). The user can choose to continue
answering the question or stop answering it.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//Question 1
System.out.println("");
String doubleQoutes1 = "[1] What code will print this statement \"Hello, World!\"?";
String doubleQoutes2 = " a.) system.Out.printIn(\"Hello, World!\"); ";
String doubleQoutes3 = " b.) System.out.printIn(\"Hello, World!\") ";
String doubleQoutes4 = " c.) System.out.printout(\"Hello, World!\"); ";
String doubleQoutes5 = " d.) System.out.printIn(\"Hello, World!\"); ";
System.out.println(doubleQoutes1);
System.out.println(doubleQoutes2);
System.out.println(doubleQoutes3);
System.out.println(doubleQoutes4);
System.out.println(doubleQoutes5);
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
if (next == 'y')
{
continue;
}
else
{
break;
}
}
//Question 2
System.out.println("");
System.out.println("[2] What is JDK?");
System.out.println(" a.) Java Developer Kit ");
System.out.println(" b.) Java Development Kit ");
System.out.println(" c.) Java Debugger Kit ");
System.out.println(" d.) Java Doc Kit ");
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
if (next == 'y')
{
continue;
}
else
{
break;
}
}
} while (ans != 'b');
//Question 3
System.out.println("");
System.out.println("[3] Which acts as a container that holds the value while the Java program is
executed? ");
System.out.println(" a.) CamelCase ");
System.out.println(" b.) Variable ");
System.out.println(" c.) Interface ");
System.out.println(" d.) Method ");
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
if (next == 'y')
{
continue;
}
else
{
break;
}
}
//Question 4
System.out.println("");
System.out.println("[4] What data type is used ti store a single character? ");
System.out.println(" a.) Floating point types ");
System.out.println(" b.) Booleans ");
System.out.println(" c.) Character ");
System.out.println(" d.) Integer ");
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
if (next == 'y')
{
continue;
}
else
{
break;
}
}
//Question 5
System.out.println("");
System.out.println("[5] Which of the following data type can store whole numbers from -32768 to
32767? ");
System.out.println(" a.) Short ");
System.out.println(" b.) Int ");
System.out.println(" c.) Byte ");
System.out.println(" d.) Long ");
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
if (next == 'y')
{
continue;
}
else
{
break;
}
}
//Question 6
System.out.println("");
System.out.println("[6] What operators are used to perform common mathematical operations? ");
System.out.println(" a.) Bitwise operators ");
System.out.println(" b.) Arithmetic operators ");
System.out.println(" c.) Logical operators ");
System.out.println(" d.) Math operators ");
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
if (next == 'y')
{
continue;
}
else
{
break;
}
}
//Question 7
System.out.println("");
System.out.println("[7] What conditional statement is used to specify a block of code to be executed,
if a specified condition is true? ");
System.out.println(" a.) else statement ");
System.out.println(" b.) switch statement ");
System.out.println(" c.) else if statement ");
System.out.println(" d.) if statement ");
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
if (next == 'y')
{
continue;
}
else
{
break;
}
}
//Question 8
System.out.println("");
System.out.println("[8] What data type is used to store a sequence of characters (text)? ");
System.out.println(" a.) Strings ");
System.out.println(" b.) Int ");
System.out.println(" c.) Boolean ");
System.out.println(" d.) Character ");
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
//Question 9
System.out.println("");
System.out.println("[9] What operators are used to assign values to variables? ");
System.out.println(" a.) Assigned operators ");
System.out.println(" b.) Bitwise operators ");
System.out.println(" c.) Assignment operators ");
System.out.println(" d.) Comparison operators ");
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
if (next == 'y')
{
continue;
}
else
{
break;
}
}
//Question 10
System.out.println("");
System.out.println("[10] What do you call the type of variable inside the value of the method and can
only use only within that method? ");
System.out.println(" a.) Static variable ");
System.out.println(" b.) Instance variable ");
System.out.println(" c.) Local variable ");
System.out.println(" d.) Dynamic variable ");
do {
System.out.println("");
System.out.print("Please enter your answer. ");
ans = scanner.nextLine().charAt(0);
System.out.print("Your answer is: " + ans); //displaying chosen answer
System.out.println("");
if (next == 'y')
{
continue;
}
else
{
break;
}
}
}
}