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

Ifs Test

star
star
star
star
star
Posljednje ažuriranje about 2 years ago
10
15
15
8.75
8.75
8.75
8.75
8.75
8.75
8.75
8.75
Pitanje 1
1.

Given a word with no spaces, determine the location of the ? in the word and then create and return a new String that does not contain a ?.

Part A – Write method findQuestionMark that will return the index position of the ? in the parameter word. All words with have at most one ?

The call findQuestionMark("dog?cat") would return 3.

The call findQuestionMark("?bigbird") would return 0.

The call findQuestionMark("squarepumpkin?") would return 13.

The call findQuestionMark("porkypig") would return -1.

The call findQuestionMark("f?atcatsonthemat") would return 1.

public static int findQuestionMark( String word )

{

//Code goes here//

}

Pitanje 2
2.

Part B – Write method removeQuestionMark that will return a new String based on the parameter word that does not contain a ?. You must call method findQuestionMark from part A. Assume that part A works as intended regardless of what you wrote in part A.

The call removeQuestionMark( "fred?flintstone" ) would return fredflintstone.

The call removeQuestionMark( "howardthe?goose" ) would return howardthegoose.

The call removeQuestionMark( "?woweeistheword" ) would return woweeistheword.

The call removeQuestionMark( "fatcatsonthemat" ) would return fatcatsonthemat.

public static String removeQuestionMark( String word )

{

//Code goes here//

}

Pitanje 3
3.

What is returned by the call go(60,78)?

public static String go(int x, int z)

{

String s = "xyz";

if(z > 60)

{

s += "def";

}

if(x <= 60)

s += "ghi";

return s;

}

Pitanje 4
4.

Consider the following code segment.

String s = "red ball";

if(s.indexOf("a")>0)

s = s + " zed";

if(s.indexOf("z")>0)

s = "alpha " + s;

out.println(s);

What will be printed as a result of executing the code segment?

Pitanje 5
5.

Consider the following code segment.

String s = "abac-adae-bfbg-bhbi";

int index = s.indexOf("b");

if(index > 0)

out.println(s.substring(index));

What will be printed as a result of executing the code segment?

Pitanje 6
6.

What is returned by the call go(7) ?

public static int go( int a )

{

int ans = 0;

if(a>=7)

{

ans += 1;

}

ans += 2;

return ans;

}

Pitanje 7
7.

What is output by the code below?

String a = "1";

String b = new String("1");

if( a == b )

{

System.out.print( "up" );

}

if( a.equals(b) )

{

System.out.print( "on" );

}

System.out.print( "at" );

Pitanje 8
8.

Consider the following code segment.

double x = 19.8;

int y = 0;

if( x > 5 )

y += 5;

if( x > 10 )

y += 10;

if( x > 15 )

y += 15;

out.print( y );

What will be printed as a result of executing the code segment?

Pitanje 9
9.

Consider the following code segment.

String s = "even";

if(s.indexOf("a")>0)

s = s + " zed";

if(s.indexOf("v")>0)

s = "alpha " + s;

out.println(s);

What will be printed as a result of executing the code segment?

Pitanje 10
10.

Consider the following code segment.

String s = "apple";

if(s.indexOf("a")>0)

s = s + " zed";

if(s.indexOf("l")>0)

s = "alpha " + s;

out.println(s);