Question

Modify the CountByFives application so that the user enters the value to count by. Start each...

Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been displayed.

public class CountByAnything
{
// Modify the code below
public static void main (String args[])
{
final int START = 5;
final int STOP = 500;
final int NUMBER_PER_LINE = 50;
for(int i = START; i <= STOP; i += START)
{
System.out.print(i + " ");
if(i % NUMBER_PER_LINE == 0)
System.out.println();
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class CountByAnything
{
  // Modify the code below
  public static void main (String args[])
  {
    final int START = 5;
    final int STOP = 500;
    final int NUMBER_PER_LINE = 10;
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter count value: ");
    int step = scanner.nextInt();
    int temp = 1;
    for(int i = START; i <= STOP; i += step)
    {
      System.out.print(i + " ");
      temp++;
      if(temp % NUMBER_PER_LINE == 0)
        System.out.println();
    }
  }
}

Output:

Enter count value: 20 5 25 45 65 85 105 125 145 165 185 205 225 245 265 285 305 325 345 365 385 405 425 445 465 485 Process f

Note: Please comment if you have any doubts below บุ。u hau e anu/ doubts

Add a comment
Know the answer?
Add Answer to:
Modify the CountByFives application so that the user enters the value to count by. Start each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I do not know how to code this. I have tried several times. Instructions CountByAnything.java +...

    I do not know how to code this. I have tried several times. Instructions CountByAnything.java + Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been displayed. 1 public class CountByAnything 2 { // Modify the code below 4 public static void main(String args[]) { Grading final int START; final int STOP = 500; final int NUMBER_PER_LINE = 10; for(int i = START; i <= STOP; i...

  • I need help asking the user to half the value of the displayed random number as...

    I need help asking the user to half the value of the displayed random number as well as storing each number generated by the program into another array list and displayed after the game is over at the end java.util.*; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in);    ArrayList<Integer> data = new ArrayList<Integer>(); int count = 0; while (!choice.equals("No")) { int randomInt =...

  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • /** * * Jumping frog game: user enters road length and series of jumps and *...

    /** * * Jumping frog game: user enters road length and series of jumps and * the program displays the current position of the frog. */ public class hw4_task5 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int playAgain = 1; int roadLen; System.out.println("JUMPING FROG"); while (playAgain == 1){ System.out.printf("Enter the length of the road: "); roadLen = in.nextInt(); play(roadLen); // Starts a new game with a road this long. System.out.printf("\nDo you want to play again...

  • using Data Structures using Java. Modify it to make the ADT resizable. For this ADT, the...

    using Data Structures using Java. Modify it to make the ADT resizable. For this ADT, the MAX_SIZE will not be final, but rather will be increased whenever an new item needs to be added and the array is full (ie. size==MAX_SIZE). Whenever the array needs to grow, add the lesser of: (i) half the current size, or; (ii) 50 additional. Have your ADT report its old and new maximum size whenever the resize operation is called by printing “ADT resized...

  • Write an expression that executes the loop while the user enters a number greater than or...

    Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds,...

  • Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values...

    Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...

  • In each of the following questions, first use NetBeans IDE to run the code (if there...

    In each of the following questions, first use NetBeans IDE to run the code (if there is an error fix it) then take a screenshot of the output and paste it under (A). In (B), justify the output you obtained in (A). - 9. Given the following: public class WorkingSheet {     public static void main(String[] args) {        B myB = new B();        A myA = new B();        System.out.print(myB instanceof A);        System.out.print(myB instanceof C);        System.out.print(myA...

  • Could someone re-write this code so that it first prompts the user to choose an option...

    Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...

  • Java Convert the QuartsToGallons program to an interactive application. Instead of assigning a value to the...

    Java Convert the QuartsToGallons program to an interactive application. Instead of assigning a value to the number of quarts, accept the value from the user as input. Given program: public class QuartsToGallons { public static final int QUARTS_IN_GALLON = 4; public static void main(String[] args) { int quartsNeeded=18; // finding required quarts System.out.println("A job that needs " + quartsNeeded + " quarts requires " + (quartsNeeded/QUARTS_IN_GALLON) + " gallons plus " + (quartsNeeded % QUARTS_IN_GALLON) + " quarts"); } }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT