What will be the value of x after the following code is executed?
int x = 5;
while (x <50)
{
x += 5;
}
a) 50
b) 45
c) Infiniteloop
d) 55
Given the following code segment: Scanner in = new Scanner (System.in);
boolean done = false;
while (!done)
{
int input = in.next();
if(input.equalsIgnoreCase("q"))
done = false;
}
What will cause the loop to terminate?
a) When the user enters -1
b) The loop will never terminate
c) When the user enters q or Q
d) When the user enters done
How many times will this for loop execute?
for (int i = 2; i < 10; i +=3)
{
...
}
a) 6
b) 3
c) 5
d) 4
A package is any program with two or more classes: True or False
Que1: What will be the value of x after the following code is executed?
int x = 5;
while (x <50)
{
x += 5;
}
a) 50
b) 45
c) Infiniteloo
Answer -: Option A - 50
Question 2 : Given the following code segment: Scanner in = new Scanner (System.in);
boolean done = false;
while (!done)
{
int input = in.next();
if(input.equalsIgnoreCase("q"))
done = false;
}
What will cause the loop to terminate?
a) When the user enters -1
b) The loop will never terminate
c) When the user enters q or Q
d) When the user enters done
Answer : Option B - The loop will never terminate
Question 3 : How many times will this for loop execute?
for (int i = 2; i < 10; i +=3)
{
...
}
a) 6
b) 3
c) 5
d) 4
Answer : Option B - 3 times
Question 4: A package is any program with two or more classes:
True or False
Answer : True
Package is a collection of related classes that we are using in our programming by reusability of the oops concepts.
What will be the value of x after the following code is executed? int x =...
1. What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) { x += y; } A. 90 B. 110 C. 210 D. This is an infinite loop 2. If a superclass has constructor(s): A. then its subclass must initialize the superclass fields (attributes). B. then its subclass must call one of the constructors that the superclass does have. C. then its subclass does not inherit...
4. Given the following code, int x = 5, n; do{ n = 0; for (int i = 0; i < x; i++) { n = n + x; System.out.println(n); } while (x > 1); a) What will be the value of x after the code segment is executed? Initial value of x 5 b) What is the output of the code segment? c) Explain how the flow of control moves in the given code segment. When explaining, show how...
Which of the following verifies that the user enters a positive integer value? A. int num = 0: Scanner s = new Scanner(System.in): do { System.out.print("Enter a positive integer: "): num = s.nextlnt(): } while (num = = 0): B. int num=0: Scanner s = new Scanner(System.in): do { System.out.print("Enter a positive integer: "): num = s.nextlnt(): } while (num % 2 ! = 0): C. int num=0: Scanner s = new Scanner(System.in): do { System.out.print("Enter a positive integer: "):...
What is the value of y after the following code is executed? int x = 20, y = 30; do { int z; z = 3 * ( y
What will be the value of x after the following code is executed? How many times will the following do-while loop be executed?
What is printed when the following code is executed? #include <stdio.h> int main() { for (int i=3, j=5; i>=0; i-=2, j+=j*i) { printf("%d", j); منم }
(a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) { System.out.println ("Hello"); x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) { sum = sum + i; i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...
Question 9 (1 point) Given that the following code has executed, what is the value of mystery? If your answer is a string, surround it with single quotes. If it is a number, just write the number. If it is a Boolean, write either True or False with no quotes. If this code won't work (crashes or infinite loop), write error with no quotes. string1 = 'I heart mathematics.' mystery' i=0 while True: 130 mysterystringl [i] if ilen (stringl)1: break
2. What is the value of x alter the following code is executed # include<iostream> using namespace std; int main int t-0, c- 0,x-3; while (c < 4) t=t+x; cout << x return 0; a) 3 b) 21 c) 24 d) 48 3. What is the output of the following code? # include<iostream> using namespace std; int main0 int a- 3; for (int i 5; i >0; i) a a+i cout << a << “ “ return 0; d) 8...
31. The following code segment is syntactically correct: int number{20}; cout << number << setbase(16) << " " << number << setbase(10) << " " << number << showpos << " " << number << endl; T__ F__ 32. The following statement wants to determine if ‘count’ is outside the range of 0 through 100: if (count < 0 && count > 100) T__ F__ 33. There is...