• Home
  • Blog
  • CISS 110 University of Kentucky Create a Java Code Computer Programming Task

CISS 110 University of Kentucky Create a Java Code Computer Programming Task

0 comments

4-17b. Update 4-17a (which is attached) that summed the numbers 1 through 10 to get 55 (1 + 2 + 3 + ….. + 9 + 10 = 55) in a while loop. Now let the user tell what number to start counting at, what number to stop counting at, and what amount to go up each number. For example, if the user wants to start at 7, go up to 19, by 4s, you will add 7 + 11 + 15 + 19 = 52 in a loop. Declare three variables (for starting number, ending number, and amount to count by) and your Scanner object and then prompt and input the three numbers from the user. Then modify the while loop into a for loop with the three parts for the start, end, and update amount, and the final print. Save as ex417b.java, run with starting at 7, going up to 19, by 4s, save the output console as ex417b.txt, attach the ex417b.java and ex417b.tx, and submit them. This is part a:

Exercise 4-17a
This program will sum 1 through 10.  Modify so the user tells the start, end, and increment
and the while loop is changed to a for loop.
*/
public class ex417a
{
	public static void main(String[] args)
	{
		int i, sum = 0;
		i = 1;
		while (i <= 10)
		{
			sum += i;
			i++;
		}
		System.out.println("Sum of 1 through 10 = " + sum);
	}
}

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}