Average
| Look at this loop to find the first space in String str ="Udacity";
boolean found = false;
String ch = "?";
int position = 0;
while (!found && position < str.length())
{
ch = str.substring(position, position + 1);
if (ch.equals(" "))
{
found = true;
}
else
{
position++;
}
}
|
"y" 7 |
|
| Look at this loop to find the first space in String str ="";
boolean found = false;
String ch = "?";
int position = 0;
while (!found && position < str.length())
{
ch = str.substring(position, position + 1);
if (ch.equals(" "))
{
found = true;
}
else
{
position++;
}
}
|
"?" 0 | |
| We are processing a series of words input by the user. We want to terminate the loop if there are adjacent duplicates. For eample, this sequence of words will terminate after the the second word cat: The pretty little cat cat is named Eliza. Complete the code below to acconmplish this. Do not use Scanner in = new Scanner (System.in);
boolean duplicate = false;
String input = "";
while (!duplicate && in.hasNext())
{
String previous = input;
input = in.next();
if (input.equals(previous))
{
//...your code here
}
else
{
//do some processing
}
}
|
duplicate = true; |
|
| What do the following nested loops display? for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
System.out.print(i + j);
}
System.out.print(" ");
}
|
0123 1234 2345 |
|
| Complete the code fragment to generate a random integer Random generator = new Random(); int x = ________________ ; |
generator.next(10) |
|
| Complete the code fragment below to generate a random integer Random generator = new Random(); int x = ________________ ; |
generator.next(10) + 1 |
|
| Complete the code random double between 0 and 100 Random generator = new Random(); double d = ________________ ; |
generator.nextDouble() * 100 |