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
Witch of the following is a valid why a scientist might a scientific theory
ad-work [718]

c i think because i new piece of info came in which changes peoples theorys

7 0
3 years ago
Write a code snippet Now write your own code snippet that asks the user to enter two numbers of integer type (one at a time) and
taurus [48]

Explanation:

num1= print("Enter a number :")

num2 = print("Enter a number :")

sum = num1 + num2

print(sum)

4 0
2 years ago
an organization that maintains a gateway to the Internet and rents access to customers on a per-use of subscription basis\ and W
shtirl [24]
1. An organisation that maintains a gateway to the internet and rent access to customers on a per use of subscription basis is called INTERNET SERVICE PROVIDER [ISP]. Internet service providers are of various forms, it can be commercially or privately owned, it can also be owned by a community. The internet access provided by ISP can be inform of cable, DSL or dial up. ISP provide other services such as website building and virtual hosting.
2. Internet protocol [IP] refers to a set of rules that guide the format of data sent over the internet, it is the method by which data is sent over the internet from one computer to another computer. Each computer that is linked to the internet has a unique IP address by which it is identified and distinguished from all other computers on the internet.
8 0
2 years ago
your brother has made a battery operated torch by using 2 cells &amp; has come to ask you how he may make the torch more powerfu
torisob [31]

Answer: Add more cells in series.

Explanation:

Adding more cells in series will add voltage which will increase the power.

5 0
3 years ago
What is Service Operations in ITIL​
Nostrana [21]

Explanation:

the objective of ITIL service operations is to make sure that IT services are delivered effectively and efficiently. the service operation life cycle stage includes the fulfilling of user requests, resolving service failure fixing problems and also carrying out routine operational tasks

7 0
3 years ago
Other questions:
  • When using the “reply all” option, your message will automatically be sent to ____ recipients of the original message. ​?
    7·2 answers
  • what is it called when you are biying and selling products via electronic channels such as the internet​
    13·2 answers
  • Joshua takes ownership of all his tasks. Which quality is he demonstrating?
    9·2 answers
  • A Layer 2 switch configuration places all its physical ports into VLAN 2. The IP addressing plan shows that address 172.16.2.250
    7·1 answer
  • Alguien me puede ayudar a arreglar mis auriculares que mi perro rompió en el conector
    5·1 answer
  • Benefits of computer in bank​
    5·1 answer
  • What is the cell reference for row 22 and column B? __________<br><br> In excel
    5·1 answer
  • An invisible path determining the way of travel from one place to another.
    10·1 answer
  • What is an advantage of storing data in a Data Lake, without applying a specific schema to it initially?
    10·1 answer
  • Imagine that you are about to make a presentation during an online meeting, where people will need to be able to see you, and yo
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!