Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I end program with user input in java?
    primarykey
    data
    text
    <p>I am currently having trouble to end my program with a users input. I currently now can only end when the user has inputted 20 numbers for example. What I want it to do is if a user inputs a number over 100, it should stop the program and display a histogram as well as a number to show the amount of times the user has inputted a number every time. Sorry if I am not making any sense, I will update this post if any further information is needed. Here is my code. </p> <pre><code>import java.util.Scanner; public class Marks { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int[] array = new int[23]; int num = 0; int count = 0; int total = 0; System.out.println ("Enter students marks in the range 0 to 100\n"); for (count = 0; count &lt;= 20; count++) { System.out.println ("Enter a number:"); num = scan.nextInt(); while (num &lt; 0 || num &gt; 100) { System.out.println ("Invalid number. Enter a valid number."); num = scan.nextInt(); } array[count] = num; total=count; } System.out.println ("How many times a number between 0-100 occur."); String[] asterisk = {"0- 29 | ", "30- 39 | ","40- 69 | ", "70- 100 | "}; //4 strings for (count = 0; count &lt;= 20; count++) { num=array[count]; if (num &lt;=29) asterisk [0] +="*"; else if (num &lt;=39) asterisk[1] +="*"; else if (num &lt;=69) asterisk[2] +="*"; else if (num &lt;=100) asterisk[3] +="*"; } for (count =0;count &lt; 4;count++) System.out.println(asterisk[count]); System.out.println("The total amount of students is " + total); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload