In Java, write a for loop that prints out the numbers starting from an integer v
ID: 3759732 • Letter: I
Question
In Java, write a for loop that prints out the numbers starting from an integer variable called start down to an integer variable call stop, in decrements of an integer variable call decrement. The printed output must be on one line and have a comma and a space between each value however no comma should be printed after the last value. No need for a class or method just the for loop and any variables associated with it. For example: if start = 1000, stop = 500 and decrement = 50, the output would be: 1000, 950, 900, 850, 800, 750, 700, 650, 600, 550, 500
Explanation / Answer
int i;
for(i = start; i >= stop+decrement; i -= decrement) //Prints number till one less than the last value with commas(,).
System.out.print(i+", ");
System.out.print(i); //Note this statement is executed outside the loop, without comma.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.