Question:

Need help on Java Programming!?

by  |  earlier

0 LIKES UnLike

Question

Write an application that prompts the user for four values and draws corresponding bar graphs using an ASCII character. For example, if the user entered 15, 12,

9, and 4, the program would draw

Output

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

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

*********

****

 Tags:

   Report

1 ANSWERS


  1. import java.util.Scanner;

    public class BarGraph {

        public static void main(String[] args) {

            Scanner input = new Scanner(System.in);

            int count = 0;

            System.out.println("Please enter 4 integers separated by spaces. ");

            System.out.println();

            

            while ((count++ < 4) && input.hasNextInt()) {

                int numColumns = input.nextInt();

                for (int col = 0; col < numColumns; col++) {

                    System.out.print('*');

                }

                System.out.println();

            }

        }

    }

    /******* output *****

    run:

    Please enter 4 integers separated by spaces.

    3 5 9 20

    ***

    *****

    *********

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

    ******/

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.