Loops Test Review: What's the Output??

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

for(int i=12; i>0; i=i-3) out.print(i);

12963

for(int i=13; i>2; i=i-2) System.out.print(i);

13119753

int ans = 0; for(int i=0; i<10; i=i+3) { ans += i; } System.out.print( ans );

18

int ans = 0; for(int i=0; i<18; i=i+3) { if( i % 2 == 0 ){ ans += i; } } System.out.print( ans );

18

int n=19, z=0; while( n > 16 ) { z = z + n; n-=4; } System.out.print( z );

19

What is output by the code below? int j=15, x=0; while(j>0) { if( j % 2 == 0) x++; j=j-3; } System.out.print( x );

2

What is output by the code below? int n=9, z=0; while( n > 4 ) { z += n; n-=2; } System.out.print( z );

21

What is output by the code below? int j=1; while(j<8) { j++; System.out.print( j ); }

2345678

What is output by the code below? int j=9, x=0; while(j>0) { x++; j=j-3; } System.out.print( x );

3

What is returned by the call go(5) ? public static int go(int x) { int cnt = 0; while(x > 0) { x = x / 2; cnt = cnt + 1; } return cnt; }

3

int ans = 0; for(int i=10; i>-1; i=i-2){ ans += i; } System.out.print( ans );

30

int t=2, x=0; while(t < 10) { x += t; t = t + 1; } System.out.print( x );

44

What is returned by the call go( 21 ) ? public static int go( int x) { int val = 0; for(int n = 1; n < x; n = n + 4){ val = val + n; } return val; }

45

What is returned by the call go( 3, 12 )? public static int go( int x, int y) { int cnt = 0; for(int n = x; n < y; n = n + 1) { if(n % 2 != 0 ) cnt++; } return cnt; }

5

What is returned by the call go( 5 ) ? public static String go( int x) { String s = ""; for(int n = x; n > 0; n = n - 2) { s = s + n + " "; } return s; }

5 3 1

for(int i=5; i<20; i=i+3) out.print(i);

58111417

What is returned by the call go( 3 )? public static int go(int x) { int q=0; while( x > 0) { q = q + x; x = x - 1; } return q; }

6

What is output by the code below? int j=3, ans=0; while(j<5) { ans+=j; j++; } System.out.print( ans );

7

for(int i=0; i<=6; i=i+2) out.print(i);

0246

What is returned by the call go( 3.5 )? public static double go( double w ) { while(w > 0) { w = w - 0.75; } return w; }

-0.25


Kaugnay na mga set ng pag-aaral

Wong Ch 16:Health Problems of School-Age Children and Adolescents

View Set

Mastering Biology-CH 6-UH-Williams

View Set

OB Module 3: The At-Risk Pregnancy

View Set

APICS CPIM Part 1, Module 5 (All)

View Set

WRIST AND HAND: TENDON RUPTURE ASSOCIATED WITH RA

View Set