1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
atroni [7]
2 years ago
7

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();
}
}
}
Computers and Technology
1 answer:
adoni [48]2 years ago
6 0

Answer:

The modified program is as follows:

import java.util.*;

public class CountByAnything{  

public static void main (String args[]){

   Scanner input = new Scanner(System.in);

final int START = 5;

final int STOP = 500;

int countBy; int count = 0;

System.out.print("Count By: ");

countBy = input.nextInt();

final int NUMBER_PER_LINE = 10;

for(int i = START; i <= STOP; i += countBy){

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

count++;

if(count == NUMBER_PER_LINE){

System.out.println();

count = 0;} } } }

Explanation:

To solve this, we introduce two variables

(1) countBy --> This gets the difference between each value (instead of constant 5, as it is in the program)

(2) count --> This counts the numbers displayed on each line

The explanation is as follows:

<em>final int START = 5; </em>

<em>final int STOP = 500;</em>

This declares countBy and count. count is also initialized to 0

int countBy; int count = 0;

This prompts the user for countBy

System.out.print("Count By: ");

This gets value for countBy

countBy = input.nextInt();

<em>final int NUMBER_PER_LINE = 10;</em>

This iterates through START to STOP with an increment of countBy in between two consecutive values

for(int i = START; i <= STOP; i += countBy){

This prints each number

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

This counts the numbers on each line

count++;

If the count is 10

if(count == NUMBER_PER_LINE){

This prints a new line

System.out.println();

And then set count to 0

count = 0;}

You might be interested in
Data ____ refers to the accuracy of the data in a database
Brilliant_brown [7]
Accuracy or quality?
7 0
2 years ago
An online bank wants you to create a program that shows prospective
ladessa [460]

Answer: I can't really code a whole thing for you but use VS Code for this it'll make your life easier in the long run.

8 0
2 years ago
Where are my files shortcut in documents folder.
faust18 [17]

Answer: Search File Explorer: Open File Explorer from the taskbar or right-click on the Start menu, and choose File Explorer, then select a location from the left pane to search or browse. For example, select This PC to look in all devices and drives on your computer, or select Documents to look only for files stored there.

Explanation: hope this helps :)

4 0
2 years ago
Assume there is an interactive math tutor. Many students take the math lessons online. At the end of each lesson, students have
Rus_ich [418]
Oh gosh oh I don’t wowiww
6 0
2 years ago
While the Internet can be a great resource, the information is not always reliable, as anyone can post information. Select one:
Olin [163]

Answer: True

Explanation: Because anyone can post something and it can be non reliable

7 0
3 years ago
Other questions:
  • What is a mortgage?
    8·2 answers
  • Free 100 point to first to answer
    5·2 answers
  • A user is attempting to format a 4 TB HDD using NTFS but only has the option to format the disk with a size of approximately 2 T
    15·1 answer
  • Which statement does not describe how to save a presentation?
    11·1 answer
  • The difrent between valid deductive argument and strong inductive argument? At least 2 example​
    6·1 answer
  • Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been
    7·1 answer
  • 4.7 code practice question 2 edhesive i cant figure out the code for this problem csn anyone help me?
    5·1 answer
  • By convention only, either the first usable address or the last usable address in a network is assigned to the router (gateway)
    11·1 answer
  • What does this map key show
    12·1 answer
  • How do you remove a key cap without a kaycap remover (keyboard keycap) ​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!