3 Replies Latest reply on Feb 4, 2007 5:24 PM by 807599

    10 numbers per line, how to?

    807599
      Ok I got this program that chooses up to 30 numbers randomly and then displays them in a random order ten from greatest to least, it does this twice. I just can't figure out how to display only 10 numbers per line. Can someone help?

      import java.io.*;
      import java.util.*;

      class APISortMain {

      public static void display(int[] a, int size){
      for(int i=0; i<size; i++){
      System.out.print(a[i]+"\t");
      }
      System.out.println();
      System.out.println();
      }

      public static void main(String args[]) throws IOException {
      Random r = new Random();
           //Arrays A = new Arrays();
      int[] able = new int[500];
      int amount = 50+r.nextInt(30);
      for(int i=0; i<amount; i++){
      able[i] = 1000+r.nextInt(5000);
      }
      System.out.println("Data unordered");
      display(able, amount);
      System.out.println("Data ordered");
      Arrays.sort(able, 0, amount);
      display(able, amount);
      amount = 50+r.nextInt(30);
      for(int i=0; i<amount; i++){
      able[i] = 1000+r.nextInt(5000);
      }
      System.out.println("Data unordered");
      display(able, amount);
      System.out.println("Data ordered");
      Arrays.sort(able, 0, amount);
      display(able, amount);
      }
      }