Exam 4: Loops
Exam 1: Introduction96 Questions
Exam 2: Fundamental Data Types103 Questions
Exam 3: Decisionseasy99 Questions
Exam 4: Loops100 Questions
Exam 5: Methods94 Questions
Exam 6: Arrays and Arraylists100 Questions
Exam 7: Inputoutput and Exception Handling100 Questions
Exam 8: Objects and Classes101 Questions
Exam 9: Inheritance and Interfaces99 Questions
Exam 10: Graphical User Interfaces54 Questions
Exam 11: Advanced User Interfaces91 Questions
Exam 12: Object-Oriented Design100 Questions
Exam 13: Recursion100 Questions
Exam 14: Sorting and Searching99 Questions
Exam 15: The Java Collections Framework100 Questions
Exam 16: Basic Data Structures94 Questions
Exam 17: Tree Structures100 Questions
Exam 18: Generic Classes78 Questions
Exam 19: Streams and Binary Inputoutput82 Questions
Exam 20: Multithreading82 Questions
Exam 21: Internet Networking74 Questions
Exam 22: Relational Databases75 Questions
Exam 23: XML74 Questions
Exam 24: Web Applications74 Questions
Select questions type
Given the following code snippet, what should we change to have 26 alphabet characters in the string str?
String str = "";
For (char c = 'A'; c < 'Z'; c++)
{
Str = str + c;
}
(Multiple Choice)
4.9/5
(36)
What is the last output line of the code snippet given below?
Int i = 5;
While (i >= 1)
{
Int num = 1;
For (int j = 1; j <= i; j++)
{
System.out.print(num + "**");
Num = num * 2;
}
System.out.println();
I = i - 1;
}
(Multiple Choice)
4.9/5
(48)
What is the output of the following code snippet?
Double a = 2;
Int n = 16;
Double r = 1;
Double b = a;
Int i = n;
While (i > 0)
{
If (i % 2 == 0) // n is even
{
B = b * b;
I = i / 2;
}
Else
{
R = r * b;
I--;
}
}
System.out.println("r = " + r);
(Multiple Choice)
4.9/5
(42)
Select the statement that correctly completes the loop in this code snippet.
Int years = 20;
Double balance = 10000;
While (years > 0)
{
__________
Double interest = balance * rate / 100;
Balance = balance + interest;
}
(Multiple Choice)
4.9/5
(38)
What is the output of the code snippet given below?
Int i = 0;
While (i != 9)
{
System.out.println("" + i);
I = i + 2;
}
(Multiple Choice)
4.7/5
(34)
How many times does the following loop run?
Int i = 0;
Int j = 1;
Do
{
System.out.println("" + i + ";" + j);
I++;
If (i % 3 == 0)
{
J--;
}
}
While (j >= 1);
(Multiple Choice)
4.9/5
(38)
Which statement about this code snippet is accurate?
Int years = 50;
Double balance = 10000;
Double targetBalance = 20000;
Double rate = 3;
For (int i = 1; i <= years; i++)
{
If (balance >= targetBalance)
{
I = years + 1;
}
Else
{
Double interest = balance * rate / 100;
Balance = balance + interest;
}
}
(Multiple Choice)
4.7/5
(36)
What will be the result of running the following code fragment?
Int year = 0;
Double rate = 5;
Double principal = 10000;
Double interest = 0;
While (year < 10)
{
Interest = (principal * year * rate) / 100;
System.out.println("Interest " + interest);
}
(Multiple Choice)
4.9/5
(45)
Which of the following statements is correct about a sentinel?
(Multiple Choice)
5.0/5
(36)
How many times does the following loop execute?
double d;
double x = Math.random() * 100;
do
{
d = Math.sqrt(x) * Math.sqrt(x) - x;
System.out.println(d);
x = Math.random() * 10001;
}
while (d != 0);
(Multiple Choice)
4.9/5
(42)
What will be the range of the random numbers generated by the following code snippet?
Int r1 = (int) (Math.random() * 50) + 1;
(Multiple Choice)
4.8/5
(39)
What is the output of the code snippet given below?
String s = "abcde";
Int i = 1;
Do
{
If (i > 1)
{
System.out.print);
}
}
While (i < 5);
(Multiple Choice)
4.8/5
(40)
Is the following code snippet legal?
Boolean b = false;
Do
{
System.out.println("Do you think in Java?");
}
While (b != b);
(Multiple Choice)
4.9/5
(48)
What will be the output of the following code snippet?
Int i;
Int j;
For (i = 0; i < 6; i++)
{
For (j = 7; j > i; j--)
{
System.out.print("*");
}
System.out.println("");
}
(Multiple Choice)
4.8/5
(30)
What is the sentinel value in the following code snippet?
Public static void main(String[] args)
{
Int age = 0;
Int sumOfAges = 0;
Int stop = 1;
Scanner reader = new Scanner(System.in);
System.out.println("Enter an age (-1 to stop): ");
Age = reader.nextInt();
While (age != -1)
{
SumOfAges = sumOfAges + age;
System.out.println("Enter an age (-1 to stop): ");
Age = reader.nextInt();
}
System.out.println("Sum of ages " + sumOfAges);
Return 0;
}
(Multiple Choice)
4.7/5
(30)
Which of the following loop(s) could possibly not enter the loop body at all?
I. for loop
II. while loop
III. do loop
(Multiple Choice)
4.8/5
(34)
How many times does the code snippet given below display "Loop Execution"?
Int i = 1;
While (i != 10)
{
System.out.println ("Loop Execution");
I++;
}
(Multiple Choice)
4.8/5
(40)
What is the output of the following code snippet?
Int f1 = 0;
Int f2 = 1;
Int fRes;
System.out.print(f1 + " ");
System.out.print(f2 + " ");
For (int i = 1; i < 10; i++)
{
FRes = f1 + f2;
System.out.print(fRes + " ");
F1 = f2;
F2 = fRes;
}
System.out.println();
(Multiple Choice)
4.7/5
(40)
What is the output of the code fragment given below?
Int i = 0;
Int j = 0;
While (i < 27)
{
I = i + 2;
J++;
}
System.out.println("j=" + j);
(Multiple Choice)
4.7/5
(42)
What is the outcome of the following code snippet?
Boolean val1 = true;
Boolean val2 = false;
While (val1)
{
If (val1)
{
System.out.println("Hello");
}
Val1 = val2;
}
(Multiple Choice)
4.9/5
(39)
Showing 41 - 60 of 100
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)