1/69
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
String a = "Hi";
String b = "Hi";
String c = a;
String d = "Hi!"
String e = newString("Hi")
System.out.println(a == c);
System.out.println(d == b);
System.out.println(a == b);
System.out.println(a == e);
true
false
true
false
a && false == false
a && true == a
a && a == a
a && !a == false
a || false == a
a || true == true
a || a == a
a || !a == true
!(!a) == a (The inverse of an inverse is the original value)
a && false == false
a && true == a
a && a == a
a && !a == false
a || false == a
a || true == true
a || a == a
a || !a == true
!(!a) == a (The inverse of an inverse is the original value)
int a = 14;
int b = -15;
int c = 22;
int d = 11;
if(a > 12 && b < -14 && c < d) {
System.out.println("YAY!!!!");
} else if (d - 20 < b) {
System.out.println("GO DO MORE PROGRAMMING!");
} else if(a + 12 >= c) {
System.out.println("This is vexing......");
} else {
System.out.println("This is very fun!");
}}
What is the output for the code above?
This is vexing......
for(int i = 0; i < 10; i++) {
if(i % 2 == 0) {
System.out.println("This is my favorite case!");
} else if(i + 6 > 12 && i % 3 == 1) {
System.out.println("There once was a pool in the back yard!");
} else {
System.out.println("Well, at least it is something...");
}
}
This is my favorite case!
Well, at least it is something...
This is my favorite case!
Well, at least it is something...
This is my favorite case!
Well, at least it is something...
This is my favorite case!
There once was a pool in the back yard!
This is my favorite case!
Well, at least it is something...
int i = 45, j = -12;
String s = "This is great!";
String s2 = "Where are you?";
if(s2.charAt(4) == ' ' && (i < 4 || j > -43) && !s2.equals("WOW!!!")) {
System.out.println("Happy days are here again!");
} else if (s2.charAt(5) == 's') {
System.out.println("Well, we are here at least.");
} else if (j + 12 != 0) {
System.out.println("The stock market is up today!");
} else if(i - 20 < 100) {
System.out.println("Where will we be having lunch tomorrow?");
} else {
System.out.println("But here you go!");
}
Where will the group be having lunch tomorrow?
int i = 12, j = -5, k = 103;
if(i < 15 && j >= -4) {
System.out.println("You should take more philosophy classes!");
} else if(!(i < 100 && k > 4)) {
System.out.println("I love medieval studies!");
} else if(!(i == 3 && k == 4)) {
System.out.println("My favorite philosopher is Radulphus Brito, of course!");
} else if(i != 4 && k == 102) {
System.out.println("My favorite philosopher is Johann Fichte.");
} else {
System.out.println("I am going to cut the grass tomorrow.");
}
My favorite philosopher is Radulphus Brito, of course!
char c = 'M';
String s = "James of Metz";
String s2 = "Albert of Sazony";
int i = 14;
if(i > 34 || c < 'B') {
System.out.println("I love Duns Scotus!");
} else if(s.charAt(9) == c) {
System.out.println("I read William of Ockham yesterday!");
} else if(!(i < 100 || s.equals("James of Metz"))) {
System.out.println("Well, I call William of Ockham 'Bill' because we're BFFs.");
} else if(s2.equalsIgnoreCase("Al")) {
System.out.println("I was reading Simon of Faversham, and he is very logical.");
} else {
System.out.println("There is nobody like Peter of Spain for a good logic read.");
}
I read William of Ockham yesterday!
What does the expression (7 != 14) evaluate to?
True
boolean x;
int y;
x = false;
y = 10;
x = !(y < 10 || y > 10);
System.out.println ( x );
What is printed?
True
What does this statement return?
int a = 2
int b = 3
a == b
Possible Answers:
false
Which is correct?
String a = "2"
String b = "2"
Is a == b correct? Or is a.equals(b) correct?
Possible Answers:
a.equals(b)
int currentYear = 2016;
bool leapYear;
if (currentYear % 4 == 0) {
leapYear = true;
} else {
leapYear = false;
}
febDays = leapYear ? is it ?28 or 29days
28
int j=6;
int k=0;
int l=2;
int c = (j|k) & l;
What is the value of c?
2
int num1 = 9;
int num2 = 5;
if (num > num2)
{ System.out.println((num1 + num2) % num2);
}
else
{ system.out.println((num1 - num2) % num2);
}
What is printed as a result of executing the code segment?
A) 0 ; b) 2 ; c) 4 ; d)9 ; E) 14
C
int var=0;
int array[4];
for (int j=0; j<=4;j++)
{
var=var+1;
}
What is the value of var?
5
#include
using namespace std;
int main()
{
int i=0;
int sum =0;
for(i;i<4;i+=2)
{
sum=sum+i;
i--;
}
return 0;
}
What is the value of i and sum?
i=3,sum=6
Suppose you have the following code:
public static void main(String[] args) {
int a =2;
if (a%2==0)
System.out.println("Hello World");
else
System.out.println("Hi");
}
Hello World
int k = arr.length;
for (int i = -1; i
k-1
public void countStatements() {
int a = 10, b = 15, c = 7;
// Start
for(int i = 0; i < a; i += 2) {
b--;
System.out.print("*");
}
for(int i = b; i >=0; i--) {
for(int j = 0; j < c; j++) {
System.out.print("*");
}
}
// End
}
1.
int j=6;
int k=0;
int l=2;
int c = (j|k) & l;
What is the value of c?
2
int value = initvalue;
if (value > 10)
if (value >15 )
value = 0;
else
value = 1;
system.out.println("Value = " + value);
under which of the condition below will this code segment print value = 1;
A) initvalue = 8;
B) initvalue = 12;
C) initvalue = 20;
d)initvalue = 0 will always be printed.
e) never code will not compile.
B
In the following equation, considering the boolean variables x, y, and z, which of the following combinations of values will evaluate to true?
(x\,\&\&\,!y)\,||\,((!x\,||\,z)\,\&\&\,!(y\,||\,z))
x == true, y == false, z == false
#include
using namespace std;
bool bigger(int x, int y)
{
if (x>y)
return true;
else
return false;
}
int main()
{
bool test;
test!=bigger(10,7);
cout<
0
2 laws of De Morgan
!True = ?
!False = ?
!(a && b) is equivalent to =?
!(a || b) is equivalent to =?
True
False
!a || b
!a && !b
if(!(x>=0) AND y<=100) convert it into something that does not have not's
if (!(x>=0) or !(Y<=100)
!(x>=0) = x<0
and
!(y<=100) = y>100
boolean a = True, b = false
if ( / missing code/)
system .out.println("Nice Job");
else
System.out.println("nicer job");
which or the following could be used to replace /missing code/ so that output of this block of code is "Nicer job"
a) a && !b
b) !a || b
c) !a && b
b & C only
(!p && !q) || !(P || q)
a) The expression always evaluates to true
b) The expression always evaluates to False
c) The expression always evaluates to P is false
d) The expression always evaluates to true when ever q is false
e) The expression evaluates to false whenever p and q have opposite truth values.
E is correct
For (int i = 209; i > 0; i /= 3)
{if (i % 2 ==0)
system.out.println( i + " ");
}
A) 200 66 22 7 2
B)66 22 7 2
c)200 66 22 2
d) 200 66 22
e) 7
C
int i = x % 50;
if x is a positive integer, which of the following could not be the value of i after the statement above execute?
A) 0
b) 10
c) 25
d) 40
e) 50
E
Assume that a, b,c have been declared and initialized with int values, The expression
! (a>b || b<=c)
is equivalent to which of the following?
A) a >b && b <= c
B) a<=b || b>c
c) a<= b && b>c
d)a = c
e)a=c
C
which condition statement is equivalent to the expression shown below?
if ((temp > 80) && !(80 < temp))
A) if (temp == 80)
B) if (temp !=80)
C) if ((temp >= 80) || (temp >80))
D) false
E) True
D
A high school class places students in a course based on their average from a pervious course. Students that have an average 92 or above are placed in an honors level course. Students that have an average below 74 are placed in a remedial level course. All other students are placed in a regular level course. Which of the the following statements correctly places the students based on the their average?
Code A)
if (average > = 92)
level = "honors";
if (average < 74)
level = " remedial";
else
level = " regular";
}
Code B)
if (average > = 92)
level = "honors";
if (average > = 74)
level = " regular";
else
level = " remedial";
}
Code C)
if (average > = 92)
level = "honors";
else if ((average >= 74) && (average <92)))
level = " regular";
else
level = " remedial";
}
A) Code A only
B) Code B only
C) Code C only
D) Code A and B only
E) code B & C only.
E
Assume that x,y and z have been declared as follows:
boolean x = true;
boolean y = false;
boolean z = true ;
which of the following expression evaluates to true?
A) x && y && z
b) x && y || z && y
c) ! (x && y) || z
d) !(x|| y ) && z
e) x && y || !z
C
Consider the following code segment
int amount = initValue;
if (amount >= 0)
if (amount < = 0)
system.out.println("**");
else
system.out.println("%%");
under what condition will this code segment print %%?
A ) initValue = -5
B) initValue = 0
C) initValue = 5
D) initValue = 10
E) initValue = 15
E
Which segment of code will correctly print the two strings name1 and name2 in alphabetical order
I ) if (name1 < name 2)
system.out.println( name1 + " " + name2);
else
system.out.println(name2 + " " + name1);
II)
if (name1.compareTo(name 2))
system.out.println( name1 + " " + name2);
else
system.out.println(name2 + " " + name1);
III)if (name1.compareTo(name 2) < 0)
system.out.println( name1 + " " + name2);
else
system.out.println(name2 + " " + name1);
A) I only
B) II only
C) III only
D) II and III only
E) I,II, and III only
C
computing the results of complex logical expression using Demorgan's law :
int a = 2, b = 3;
boolean result1 = !(b == 3 && a < 1); what is the output
True /False?
True
computing the results of complex logical expression using Demorgan's law :
int a = 2, b = 3;
boolean result2 = !(a != 2 || b < = 4);; what is the output
True /False?
False
int count = 0;
int total = 0;
boolean result = (count != 0 && total/count > 0); what is the output, True/False?
False
What is the output of the below code?
for (int i = 0 ; i <3 ; I ++)
{ system.out.printlin("Hello");
}
Hello
Hello
Hello
for (int j = 9; j > 6 ; J--)
{ system.out.println( j + " ");
system.out.println(10 - j);
}
9 1
8 2
7 3
for (int k = 1; k <= 4;K++)
{ system.out.println(k);
}
system.out.println(k*10);
Compile - time error K cannot be resolved to a variable
int i ;
for (i = 1; i < 5; i ++)
{ system.out.println(i);
}
system.out.println(i);
1
2
3
4
5
nested loops:
for (int i = 0,i < 3; i ++)
{
for ( int j =1,j <5,j++)
{
system.out.println(i + " " + j);
}
}
0 1
0 2
0 3
0 4
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4
for (int x = 4; x > 0 ; X --)
{
for (int y = 9 ; y < = 15 ; y ++)
{ total time the loop executes
}
}
28 times the loop executes.
consider the following code segment
int count = 1;
int value = 31;
while (value >= 10)
{ value = value - count;
count = count + 3;
}
system.out.println(value);
What is printed as a result of executing the code segment ?
A) 4
B) 9
c) 10
D)13
E)31
B
Consider the following code segment.
int count = 5;
for ( int = 3 ; i <7; i = i+2)
{ count + = 1;
}
system.out.println(count);
What is printed as a result of executing the code segment?
A) 5
B) 7
C)9
D)13
E)20
D
Consider the following code segment
int incr = 1;
for (int i = 0; i < 10; I + = incr)
{ system.out.println (i - incr + " ");
}
what is printed as a result of executing the code segment?
A) -1 0 2 5
B) -1 0 3 7
C) -1 1 4 8
D) 0 2 5 9
E)0 1 3 7
A
Which of the following code segments will print exactly eight " $" symbols?
I ) for ( int i =0 ; i < 8; i ++)
{ system.out.print("$");
II) int i = 0;
while (i < 8)
{ system.out.println("$");
I++;
}
III) for ( int i = 7; i <= 30; i+=3)
{ system.out.println("$");
}
A) I only
B) II only
C) I and II only
D) I and III only
E) I , II, and III
E
Consider the following code segments.
int a = / value supplied with in program/
int b = / value supplied with in progoram /
if ( / missing condition /)
{ int result = a +b;
}
which of the following should replace / missing condition / to ensure that a+b will not be too large to be held correctly in result?
A) a + b < Intetger.MAX_Value
B) a +b <= Integer.MAX_Value
C)Integer.MIN_Value + a <= b
D)Integer.MIN_Value - a <= b
E)Integer.MIN_Value - a >= b
E
Consider the following code segment
for (int j = 0; j < 10 ; j++)
{ for ( int k = 10 ; k > j ; k --)
{ systme.out.println("*");
}
}
How many "*" symbols are printed as a result of executing the code segment ?
A) 5, B)10,C)45,D)55,E)100
D
Consider the following code segment.
boolean b1 = true ;
boolean b2 = true;
int x = 7;
while ( b1 || b2)
{ if (x > 4)
{ b2 = !b2 ;
}
else
{ b1 = !b1;
}
x--;
}
system.out.print(x);
What is printed as a result of executing the code segment?
A) 3,B)4,c)6,D) 7,E) Nothing will be printed ; infinite loop.
A
Which of the following three code segments will produce the same output?
I) int i = 1;
while
(i <12)
{ system.out.print(i + " ");
I*=2;
}
II) for (int i = 4 ; i > 0 ; i --)
{ system.out.print((4-i) * 2 +1 + ' ");
}
III) for ( int i =0 ; i <4 ; i ++)
{ system.out.print((int)Math.pow(2.i) + " "}'
}
A ) I and II only
B) II and III only
C) I and III only
D) I,II, and III
E) all three outputs are different.
C
Consider the following code segment
double count = 6.0;
for (int num = 0;num < 5; num ++)
{ if (count ! = 0 && num/count > 0)
{ count - = num;
}
}
system.out.println(count);
What is printed as a result of executing the code segment?
A) 0.0 B) -4.0 C)5 D) the program will end successfully , but nothing will be printed.
E) Nothing will be printed. Run-time error : Arithemeti cexception.
A
int n = 0;
while (n <20)
{ system.out.print(n % 4 + " ");
if ( n % 5 == 2)
{ n + = 4 ;
} else
{ n +=3;
}
}
what is printed as a result of executing the code segment?
A) 0 3 2 1 0 0 3
B) 0 0 3 2 2 1
c) 0 3 2 1 0 0
D) 0 0 3 2 2 1 0
E Many numbers will be printed ; infinite loop.
A
consider the following code segment
double tabulate = 100.0;
int repeat = 1;
while ( tabulate > 20 )
{ tabulate = tabulate - math.pow(repeat ,2);
repeat ++;
}
system.out.println(tabulate);
what is printed as a result of executing the code segment?
a) 20.0 B) 6.0 C) 19.0 D) 9.0 E) -40.0
C
What does the following segment of java code print out?
double x = 4 4.5;
int y = (int)x ;
system.out.println(x+" "+y);
4.5 , 4
what does the following segment of java code print out?
int x = 7, y = 3;
int z = x/y + x%y;
if (z ==y)
x++;
System.out.println(X+" "+y+" "+z);
8 3 3
What does the following segment of java code print out?
for (int i =1;i <30; i = i+3)
{ if (i %2 == 0)
system.out.print((i/2) + " ");
}
System.out.println();
2,5,8,11,14
What does the following segment of jave code do in general?
scanner stdin = new scanner (system.in);
System.out.println("enter n ,");
int n = stdin.nextint();
int total = 0;
while ( n>0)
{ total = total + n %10;
n=n/10;
}
system.out.println(total);
This segment of code prints out the sum of the digits of the original value of n entered by the user.
which of the following Boolean expression are equivalent ? ( Assume that x and y are intergers variables that have been initialized with the intended values)
i) ((x>0) && (Y>0)) || ((X>0) && (Y<0))
ii) X! = Y
iii) (x>0) && (y!=0)
iv) (x>0) && (x+y ! =x)
A ) i & ii
B) i and iii
C) i , iii, iv
D) ii, iii,iv
E ) All 4 are different , logically.
C
The Boolean expression !(A||B) is equvalent to which of the following?
A) !A || !B
B) !A || B
C) !A && !B
D)!A && B
E) None of the Above
C
What values are stored in x and y after execution of the following program segment.?
int x = 30, y = 40;
if (X> = 0)
{ if (x<=100)
{ y = x*3;
if (y<50)
x/=10;
}
Else
y = x*2;
}
else
y =-x;
A) x=30,y = 90
B ) x = 30 Y = -30
C) x =30, y= 60
D)x=3,y=-3
E)x=30,y= 40
B
Which of the following will evaluate to true only if boolean expressed A,B,C are all false?
A) ! A && !(B && !C)
B) !A || !B ||!C
C)! (A || B || C)
D) ! ( A && B && B && C)
E) !A || !(B || C)
Assume that a and b are integers . The boolean expression
!(a <= b) && (a* b >0)
will always evaluate to true given that
A) a = b
B) a > b
C) a < b
D) a> b and b >0
E) a > b and b < 0
Given that a, b, and c are integers, consider that Boolean expression
(a < b) || ! ((c ++ a * b) && (c< a))
Which of the following will guarantee that the expression is true ?
A) C < a is false
B) C < a is true
C) a < b is false
D) c === a * b is true
E) c == a * b is true , and c < a is true
In the following code segment, you may assume that a,b and n are all type int
if (a ! = b && n/ (a-b) > 90)
{
/ statement 1/
}
else
{
/ statement 2 /
}
/ statement 3/
A) What will happen if a == b is false?
B) / statement 2 /
C)Either ? Statement 1 / or ? Statement 2 / will be executed
D) A compile time error will occur
E) An exception will be thrown.
Given that n and count are both of type int, which statement is true about the following code segments?
I ) for ( count = 1 ; count < = n ; count ++)
system.out.println(count);
II) count =1
while (count < = n)
{ system.out.println(count);
count++
}
A ) I and II are exactly equivalent for all input value n.
B) I and II are exactly equivalent for all input values n > = 1, but differe when n<= 0.
C) I and II are exactly equivalent only when n= 0.
D) I and II are exactly equivalent only when n is even.
E) I and II are not equivalent for any input values of n.
int x = 10 , y = 0;
while (x> 5)
{
y = 3;
while (y
What output will be produced by this code segmetn ?
for int( i = 5;i>=1;i--)
{ for (int j = 1; j>=1;j--)
system.out.print(2* j-1);
system.out.println();
}
A) 9 7 5 3 1
9 7 5 3
9 7 5
9 7
9
B) 9 7 5 3 1
7 5 3 1
5 3 1
3 1
1
C) 9 7 5 3 1
7 5 3 1 -1
5 3 1 -1 -3
3 1 -1 -3 -5
1 -1 -3 -5 -7
D) 1
1 3
1 3 5
1 3 5 7
1 3 5 7 9
E) 1 3 5 7 9
1 3 5 7
1 3 5
1 3
1