Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class CountingNumbers {
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- echo("Input 30 numbers from 1-100\n");
- ArrayList<Integer> nums = new ArrayList<Integer>();
- int x = 0;
- while ((kb.hasNext()) && (x < 30)) {
- nums.add(kb.nextInt());
- x++;
- }
- echo("Inputted Numbers:");
- showArr(nums);
- echo("Sorted:\n");
- int a = 0, b = 0,c = 0,d = 0,e = 0,f = 0,g = 0,h = 0, i =0,j = 0;
- x = 0;
- while (x < nums.size()) {
- if (nums.get(x) < 11) {
- a++;
- }
- else if (nums.get(x) < 21) {
- b++;
- }
- else if (nums.get(x) < 31) {
- c++;
- }
- else if (nums.get(x) < 41) {
- d++;
- }
- else if (nums.get(x) < 51) {
- e++;
- }
- else if (nums.get(x) < 61) {
- f++;
- }
- else if (nums.get(x) < 71) {
- g++;
- }
- else if (nums.get(x) < 81) {
- h++;
- }
- else if (nums.get(x) < 91) {
- i++;
- }
- else if (nums.get(x) < 101) {
- j++;
- }
- x++;
- }
- echo("\n1-10\t");
- while (a > 5) {
- echo("*");
- a = a - 5;
- }
- echo("\n11-20\t");
- while (b > 5) {
- echo("*");
- b = b - 5;
- }
- echo("\n21-30\t");
- while (c > 5) {
- echo("*");
- c = c - 5;
- }
- echo("\n31-40\t");
- while (d > 5) {
- echo("*");
- d = d - 5;
- }
- echo("\n41-50\t");
- while (e > 5) {
- echo("*");
- e = e - 5;
- }
- echo("\n51-60\t");
- while (f > 5) {
- echo("*");
- f = f - 5;
- }
- echo("\n61-70\t");
- while (g > 5) {
- echo("*");
- g = g - 5;
- }
- echo("\n71-80\t");
- while (h > 5) {
- echo("*");
- h = h - 5;
- }
- echo("\n81-90\t");
- while (i > 5) {
- echo("*");
- i = i - 5;
- }
- echo("\n91-100\t");
- while (j > 5) {
- echo("*");
- j = j - 5;
- }
- }
- public static void echo(Object o) {
- System.out.print(o);
- }
- public static void showArr(ArrayList<Integer> arr) {
- int size = arr.size();
- int i = 0;
- while (i < size) {
- if (i == (size - 1)) {
- System.out.print(arr.get(i) + "]\n");
- }
- else if (i == 0) {
- System.out.print("[" + arr.get(i) + ", ");
- }
- else {
- System.out.print(arr.get(i) + ", ");
- }
- i++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement