Write a loop that reads positive integers from standard input, printing out those values that are greater than 100, each followed by a space, and that terminates when it reads an integer that is not positive. Declare any variables that are needed. ASSUME the availability of a variable , stdin , that references a Scanner object associated with standard input. int number = 0; while (stdin.hasNextInt() && number >= 0){ number =stdin.nextInt(); if (number > 100) System.out.print(number + " "); }
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; }
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 . total=0; k=0; do{ total+=k*k*k; k++; } while (k<=n);
Comments
Post a Comment