• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/15

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

15 Cards in this Set

  • Front
  • Back

The flow of control that programmers use to complete jobs with this pattern is called _____ or _____.

looping or repetition

one execution of the loop body

iteration

one or more statements that could cause the loop condition to evaluate to false (and thus end the looping)

loop update

the event that causes the loop condition to evaluate to false

loop termination condition

If the loop condition never evaluates to false, the loop body is executed continuously, without end. This is called _____ or _____.

an endless loop or an infinite loop

How can we stop an infinite loop?

Abort the program

20678: Given an int variable k that has already been declared, use a while loop to print a single line consisting of 88 asterisks. Use no variables other than k.

k = 0;


while (k < 88)


{


System.out.print("*");


k = k + 1;


}

20679: Given an int variable n that has already been declared and initialized to a positive value, use a while loop to print a single line consisting of n asterisks. Use no variables other than n.

while (n != 0)


{


System.out.print("*");


n = n - 1;



}

21000: Given an int variable n that has already been declared, write some code that repeatedly reads a value n until at last a number between 1 and 10 (inclusive) has been entered. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.

do


{


n = stdin.nextInt();


}


while (n>10 || n < 1);

21001: Given a string variable response that has already been declared, write some code that repeatedly reads a value from standard input into response until at last a Y or y or N or n has been entered. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.

do


{


response = stdin.next();


}


while (!response.equals("Y") && !response.equals("y") && !response.equals("N") && !response.equals("n"));

21208: Given a String variable named line1 and given a Scanner reference variable stdin that has been assigned a reference to a Scanner object, read the next line from stdin and save it in line1.

line1 = stdin.nextLine();

21216: Given a Scanner reference variable named input that has been associated with an input source consisting of a sequence of strings and two int variables, count and longest, write the code necessary to examine all the strings in the input source and determine how long the longest string (or strings are). That value should be assigned to longest; the number of strings that are of that length should be assigned to count.

count = 0;


longest =0;


String myString = new String();


while (input.hasNext())


{


myString = input.next();


if (myString.length() == longest)


count++;


else if (myString.length() > longest)


{


longest = myString.length();


count = 1;


}


}

20680: Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total. Thus your code should put 1*1 + 2*2 + 3*3 + … + 49*49 + 50*50 into total. Use no variables other than k and total.

total = 0;


k = 1;


while (k <= 50)


{


total += (k*k);


k = k+1;


}

20682: Given an int variable k that has already been declared, use a do…while loop to print a single line consisting of 53 asterisks. Use no variables other than k.

k = 0;


do


{


System.out.print("*");


k++;


}


while (k < 53);

20685: Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Use no variables other than n, k, and total and do not modify the value of n.

k = n;


total = 0;


while (k > 0)


{


total = total + k*k*k;


k--;


}