Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a while loop that prints out the numbers starting from an integer variable

ID: 3759584 • Letter: W

Question

Write a while 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 while 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

public class Print {  

   public static void main(String[] args) {

       int start = 1000;

       int stop = 500;

       int decrement = 50;

       for (int i=start; i>=stop; i=i-decrement) {

           System.out.print(i+", ");

       }

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote