Showing posts with label Java Program. Show all posts
Showing posts with label Java Program. Show all posts

Given an int variable n that has already been declared, write some code that repeatedly reads a value into n until at last a number between 1 and 10 (inclusive) has been entered.

Given an int variable n that has already been declared, write some code that repeatedly reads a value into 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);

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.

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 = 0 ;
total = 0 ;
while ( k <= n )
{
total = total += k k k;
k++ ;
}

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 11 + 22 + 33 +... + 4949 + 50*50 into total. Use no variables other than k and total.

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 11 + 22 + 33 +... + 4949 + 50*50 into total. Use no variables other than k and total.



total=0;
for (k=1;k<=50; k++)
total+=k*k;