Preskoči na glavni sadržaj
Prijava
Sign up for FREE
arrow_back
Biblioteka

For Loops Quiz

star
star
star
star
star
Posljednje ažuriranje about 2 years ago
14
1
1
1
1
1
1
1
1
1
1
1
1
1
7
Pitanje 1
1.

What is output by the code below?

for(int i=0; i<=10; i=i+2)

out.print(i);

Pitanje 2
2.

What is output by the code below?

for(int i=20; i>0; i=i-4)

out.print(i);

Pitanje 3
3.

What is output by the code below?

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

out.print(i);

Pitanje 4
4.

What is output by the code below?

for(int i=15; i>2; i=i-2)

System.out.print(i);

Pitanje 5
5.

What is output by the code below?

int ans = 0;

for(int i=10; i>-1; i=i-2)

ans += i;

System.out.print( ans );

Pitanje 6
6.

What is output by the code below?

int ans = 0;

for(int i=0; i<12; i=i+3)

ans += i;

System.out.print( ans );

Pitanje 7
7.

What is output by the code below?

int ans = 0;

for(int i=0; i<20; i=i+3)

if( i % 2 == 0 )

ans += i;

System.out.print( ans );

Pitanje 8
8.

What is returned by the call go( 7 ) ?

public static String go( int x)

{

String s = "";

for(int n = x; n > 0; n = n - 2)

s = s + n + " ";

return s;

}

Pitanje 9
9.

What is returned by the call go( 17 ) ?

public static int go( int x)

{

int val = 0;

for(int n = 1; n < x; n = n + 4)

val = val + n;

return val;

}

Pitanje 10
10.

What is returned by the call go( 7, 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;

}

Pitanje 11
11.

int tot = 0;

for( int i=2; i<17; i++ ) {

tot = tot + i;

}

out.println( tot );

Pitanje 12
12.

int count=0;

for(int j=4; j<23; j++) {

if(j%2==1)

count++;

}

out.println( count );

Pitanje 13
13.

int sum=0;

for(int m=5; m<18; m++) {

if(m%2!=1)

sum=sum+m;

}

out.println(sum);

Pitanje 14
14.

DIRECTIONS : Write a return method named loopy that returns a String. loopy takes in two parameters - an integer named count and an String named value. loopy will return a new String containing count copies of value.

loopy( "dog", 3 ) returns "dogdogdog"

public static String loopy(String value,int cnt )

{

//Code goes here.

}