16.9k views
5 votes
One interesting application of computers is to display graphs and bar charts. Write an application that reads five numbers between 1 and 30. For each number that’s read, your program should display the same number of adjacent asterisks. For example, if your program reads the number 7, it should display *******. Display the bars of asterisks after you read all five numbers.

User MohamedEzz
by
7.1k points

1 Answer

3 votes

Answer:

The answer to this question can be given by program that are as follows

import java.util.*;

//import package for taking input from user.

public class Main //define class

{

public static void main (String ag[] ) //define main function

{

int number;

Scanner input = new Scanner(System.in);

for (int i = 0; i < 5; i ++) //loo for input.

{

System.out.print ("Enter a number between 1 - 30: ");

number = input.nextInt(); //input number by the user.

}

asterisk(); //calling function.

}

public static void asterisk() //defination of function.

{

//body of function.

int n; //local variable.

for (n= 0; n <= 30; n++) //using loop for print asterisk

{

if (n !=0)

//printf used for print value.

System.out.printf("*", n ); //print value.

}

for (n= 0; n <= 30; n++) //using loop for print asterisk

{

if (n !=0)

//printf used for print value.

System.out.printf("*", n ); //print value.

}

for (n= 0; n <= 30; n++) //using loop for print asterisk

{

if (n !=0)

//printf used for print value.

System.out.printf("*", n ); //print value.

}

for (n= 0; n <= 30; n++) //using loop for print asterisk

{

if (n !=0)

//printf used for print value.

System.out.printf("*", n ); //print value.

}

for (n= 0; n <= 30; n++) //using loop for print asterisk

{

if (n !=0)

//printf used for print value.

System.out.printf("*", n ); //print value.

}

}

}

Output:

Enter a number between 1 - 30: 2

Enter a number between 1 - 30: 2

Enter a number between 1 - 30: 1

Enter a number between 1 - 30: 3

Enter a number between 1 - 30: 4

*******************************************************************************

Step-by-step explanation:

In this program we take 5 time input from the user and print the value in the form of (*) that can be explain in above output section.In that program we use printf method that is also used for print the value.

User Oliver Leung
by
6.6k points