Conditionals Test

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Write a line of code that creates a random integer value between (-3, 107)

int a= (int)Math.random()*111-3;

List all the possible combinations of A, B, and C such that:: A&&B||!C will be TRUE

a b c t t f t t t f t f

what is the output:: String a = "Dog"; String b = "cat"; out.println(b.compareTo(a));

a positive number

what is the output:: int a=7, b=11; if (a<b) { if (a<20) a *= 2; else a = b-a; b = b/3; } else{ if(b<15) b = b*2+3; else b = a-b+15; a = a/4; }

a=14 b=3

what is the output:: int n=70, s=81; if (n>30) { if (s>90) out.print("go"); }else out.print("stop"); out.print("aplus");

aplus

what is the output:: String sNine = "abc"; String sTen = "ABC"; if (sNine.charAt (0)==sTen.charAt(0)) out.print ("equal") else if (sNine.chatAt(0)>sTen.charAt(0)) out.print("bigger"); else if (sNine.chatAt(0)<sTen.charAt(0)) out.print("smaller");

bigger

what values will be stored in c and d after execution of the code:: int c=5, d=10; if (d>c) { if (c>50) c /= 2; else c = d-c; d = d/5; } else{ c = c/2; d = d/2+3; }

c=5 d=2

what values will be stored in c and d after execution of the code:: int c=12, d=3; if (d>c) { if (c>50) c /= 2; else c = d-c; d = d/5; } else { c = c/2; d = d/2+3; }

c=6 d=4

what is the output:: int w= 50, x=68; if (w>50) if (x>60) out.print("it"); else out.print("at"); else out.print("up"); out.print("fun");

upfun

Assume the following conditional statement: A||B&&C. Which Boolean compound operator would be evaluated 1st?

B&&C

what is the output:: int e= -4; if(! (e>0)) System.out.print ("fun"); System.out.print ("go");

fungo

what is the output:: int numA=100, numB=17; if (numA>90) if (numB>10) out.print("go"); out.print("nogo");

gonogo

what is the output:: int a=105, b=120; if (a>90) if (b>100) out.print("go"); else if (b>90) out.print("it"); else out.print("up"); out.print("on");

goon

Write code that will print out "of age!" if a number x is between the values 21 and 55 inclusive

if ((x>=21)&&(x<=55) { Systen.out.printlm("of age!"); }

Write code that will print out "This is it!" if the String variable a is equal to the String variable b.

if (a.equals.(b)) { System.out.println("This is it!"); }

Write code that will print out "LITTLE" when the String str1 smaller than or equal to the String str2, and "BIG" otherwise.

if (str1.equals.(str2)) { System.out.println ("LITTLE"); } else { System.out.println("BIG"); }

Write code will perform the following function: x+15 x<10 y= x-10 x>55 x/2 otherwise

if (x<10) { y= x+15; } else if (x>55) { y= x-10; } else { y= x/2; }

What is the output:: int a = 95, b = 100; if (a>90) if (b>100) out.print("go"); else if (b>90) out.print("it"); else out.print("up"); out.print("on");

iton

what is the output:: int c = 11; if (c>3 && c>10) System.out.print("it"); System.out.print("up");

itup

what is the output:: int c = 8; if (c>10 || c>5) System.out.print("it"); System.out.print("up");

itup

what always goes first: || or &&

&&

what is returned by the call go (2):: public static String go( int a ) { if (a>=0) { if (a>=1) return "1"; return "2"; } return "3"; }

13

what is the output:: int a = 40; out.print("1"); if (a>=50) out.print("2"); out.print("3");

13

what is the output:: int a = 40; if(a>=50 { out.print("1"); if (a>=30) out.print("2"); } out.print("3");

3

what is returned by the call go (9):: public static String go( int a ) { int ans = 0; if (a>=0) { if (a>=1) ans += 1; ans += 2; } ans += 3; return ans; }

6

what is the output:: int numE=100, numF=10; if (numE>90) if(numF>10) out.print("go"); else out.print("run"); else out.print("fly"); out.print ("nogo");

runnogo

what is the output:: String one = "ABC"; String two = "abc"; if (one.charAt (0)==two.charAt(0)) out.print ("equal") else if (one.chatAt(0)>two.charAt(0)) out.print("bigger"); else if (one.chatAt(0)<two.charAt(0)) out.print("smaller");

smaller

what is the output:: int u=100, v=88; if (u>90) if(v>95) out.print ("def"); else out.print ("xyz"); else out.print ("ghi"); out.print ("fun");

xyzfun


Ensembles d'études connexes

Chapter 1 Humans and the Microbial World

View Set

L3: Other/Another/The other/Others

View Set

Biology Plants and Photosynthesis Unit Test

View Set

Ramsey classroom post test chapter 5

View Set

MKTG 633 Sample Multiple Choice 10 Each Chapter

View Set