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]
3 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]3 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
20 Points! What are some ways to insert a row or column? Check all that apply.
mars1129 [50]

Answer:

hi its me

Explanation:

5 0
4 years ago
Read 2 more answers
The company where Derek works has tasked him with setting up and securing a SOHO router. He wants to make sure the wireless netw
sp2606 [1]

Change default user name and password is the first step that should be performed by Derek to secure the wireless router

<h3><u>Explanation:</u></h3>

The device that helps in accessing internet or to any private computer network is the wireless router. It is a devices that acts as the access point which is wireless in nature. There are many steps involved in securing  the wireless router. If the wireless router is not secured then it will be used by others without our knowledge.

In order to secure the wireless router firstly we should create our won password and username deleting the default username and password.To do this, we must open router setting page and change the default username and password with our own. The SSID name of the network must also be changed.

6 0
4 years ago
Choose the answer that best explains why Morse's invention of the telegraph changed media forever.
Alex73 [517]

Just had this question, the correct answer is

It was the first form of media that did not require people to physically transport the information.

7 0
3 years ago
Read 2 more answers
What is the group scope for domain admins, domain controllers, and domain users default groups?
Igoryamba
The group of domain admins, domain controllers, and domain users default group is global. Thank you for posting your question here at brainly. I hope the answer will help you. Feel free to ask more questions.
4 0
3 years ago
Need help finding the totals and with the empty spots
Lunna [17]

Answer:

weff WEF ef ef aeF EFaef  EFE  fe efaef ea f

Explanation:

8 0
3 years ago
Other questions:
  • Using the expected format, of putting key information where the reader can’t find it, is an example of?
    8·2 answers
  • To find the largest number in a list of numbers, use the _____.
    8·1 answer
  • Physical activity such as sports or even a brisk walk can help reduce
    7·2 answers
  • Harmful programs used to disrupt computer operation, gather sensitive information, or gain unauthorized access to computer syste
    7·1 answer
  • Tim is creating a page to display his poker club’s set of rules. He has main categories and subcategories along with about a par
    12·1 answer
  • 2) Show the decimal equivalent of each of the numbers if they are interpreted as (4 answers): 11001101 01101001 a. Unsigned bina
    15·2 answers
  • Student aid is based on either financial need or _____ need.
    12·2 answers
  • Problem # 1 [End of chapter problem] The following character encoding is used in a data link protocol: A: 01100111 B: 11110011 F
    14·1 answer
  • A class can inherit behavior from a parent but also define its own and override parent behavior. This is called:
    8·1 answer
  • To what extent do you agree with the assertion that “Collection development begins with community analysis”. (Give reasons to bu
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!