Advertisement
illpastethat

CountingNumbers

Mar 8th, 2012
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class CountingNumbers {
  5.     public static void main(String[] args) {
  6.         Scanner kb = new Scanner(System.in);
  7.         echo("Input 30 numbers from 1-100\n");
  8.         ArrayList<Integer> nums = new ArrayList<Integer>();
  9.         int x = 0;
  10.         while ((kb.hasNext()) && (x < 30)) {
  11.             nums.add(kb.nextInt());
  12.             x++;
  13.         }
  14.         echo("Inputted Numbers:");
  15.         showArr(nums);
  16.         echo("Sorted:\n");
  17.         int a = 0, b = 0,c = 0,d = 0,e = 0,f = 0,g = 0,h = 0, i =0,j = 0;
  18.         x = 0;
  19.         while (x < nums.size()) {
  20.             if (nums.get(x) < 11) {
  21.                 a++;
  22.             }
  23.             else if (nums.get(x) < 21) {
  24.                 b++;
  25.             }
  26.             else if (nums.get(x) < 31) {
  27.                 c++;
  28.             }
  29.             else if (nums.get(x) < 41) {
  30.                 d++;
  31.             }
  32.             else if (nums.get(x) < 51) {
  33.                 e++;
  34.             }
  35.             else if (nums.get(x) < 61) {
  36.                 f++;
  37.             }
  38.             else if (nums.get(x) < 71) {
  39.                 g++;
  40.             }
  41.             else if (nums.get(x) < 81) {
  42.                 h++;
  43.             }
  44.             else if (nums.get(x) < 91) {
  45.                 i++;
  46.             }
  47.             else if (nums.get(x) < 101) {
  48.                 j++;
  49.             }
  50.             x++;
  51.         }
  52.         echo("\n1-10\t");
  53.         while (a > 5) {
  54.             echo("*");
  55.             a = a - 5;
  56.         }
  57.         echo("\n11-20\t");
  58.         while (b > 5) {
  59.             echo("*");
  60.             b = b - 5;
  61.         }
  62.         echo("\n21-30\t");
  63.         while (c > 5) {
  64.             echo("*");
  65.             c = c - 5;
  66.         }
  67.         echo("\n31-40\t");
  68.         while (d > 5) {
  69.             echo("*");
  70.             d = d - 5;
  71.         }
  72.         echo("\n41-50\t");
  73.         while (e > 5) {
  74.             echo("*");
  75.             e = e - 5;
  76.         }
  77.         echo("\n51-60\t");
  78.         while (f > 5) {
  79.             echo("*");
  80.             f = f - 5;
  81.         }
  82.         echo("\n61-70\t");
  83.         while (g > 5) {
  84.             echo("*");
  85.             g = g - 5;
  86.         }
  87.         echo("\n71-80\t");
  88.         while (h > 5) {
  89.             echo("*");
  90.             h = h - 5;
  91.         }
  92.         echo("\n81-90\t");
  93.         while (i > 5) {
  94.             echo("*");
  95.             i = i - 5;
  96.         }
  97.         echo("\n91-100\t");
  98.         while (j > 5) {
  99.             echo("*");
  100.             j = j - 5;
  101.         }
  102.     }
  103.     public static void echo(Object o) {
  104.         System.out.print(o);
  105.     }
  106.     public static void showArr(ArrayList<Integer> arr) {
  107.         int size = arr.size();
  108.         int i = 0;
  109.         while (i < size) {
  110.             if (i == (size - 1)) {
  111.                 System.out.print(arr.get(i) + "]\n");
  112.             }
  113.             else if (i == 0) {
  114.                 System.out.print("[" + arr.get(i) + ", ");
  115.             }
  116.             else {
  117.                 System.out.print(arr.get(i) + ", ");
  118.             }
  119.             i++;
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement