Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been displayed. Save the file as CountByAnything.java.public class CountByFives{public static void main(String args[]){for (int i = 5; i <= 200; i = i + 5) {System.out.print(i+",");if (i % 50 == 0){System.out.println();}}}}

Answer :

ammary456

Answer:

import java.util.Scanner;

public class CountByAnything

{

  public static void main (String args[])

  {

      int beginning = 5;

      int ending = 200;

      Scanner s = new Scanner(System.in);

      System.out.println("Enter the value to count by:");

      int valueToCount = s.nextInt();

      int counter = 0;

      for(int i = beginning; i <= ending; i += valueToCount)

      {

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

          if((counter+1) % 10 == 0)

              System.out.println();

          counter++;

      }

  }

}

Explanation:

  • Initialize the beginning and ending.
  • Loop through the value of ending variable.
  • Check if numbers per line is equal to ten  and Increment the counter .

         

Other Questions