Arlong Park Forums

    • Register
    • Login
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Java help please

    Help Forums
    3
    3
    2487
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Chimcham
      Chimcham
      last edited by
      Chimcham
      spiral
      Chimcham
      spiral

      I have an annoying problem with the array I made

      When I run the program it does not print nicely and on different lines. Its just one long line. When I add "+ " " " to the println it puts a space between every number in the array which is bothering me.

      where did I go wrong?

      import java.util.Arrays;
      import java.util.Scanner;

      public class Sorter {

      public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      System.out.println("Input array size");
      int arraySize = input.nextInt();
      int originalArray[] = new int[arraySize];
      for (int i = 0; i < originalArray.length; i++){
      originalArray = (int)(Math.random() * 101);
      System.out.print(originalArray
      ); //print#1
      System.out.println();
      }

      int selectionSortedArray[] = new int[arraySize];
      for (int j = 0; j < selectionSortedArray.length; j++){
      selectionSortedArray[j] = (int)(Math.random() *101);
      performSelectionSort(selectionSortedArray);
      System.out.print(selectionSortedArray[j]); // print number 2
      System.out.println();
      }
      int utilSortedArray[] = new int[arraySize];
      for (int s = 0; s < utilSortedArray.length; s++){
      utilSortedArray = (int)(Math.random() * 101);
      Arrays.sort(utilSortedArray);
      Arrays.equals(selectionSortedArray, utilSortedArray);
      System.out.print(utilSortedArray
      ); // print #3
      System.out.println();
      }

      }

      public static void performSelectionSort(int[] a) {
      int i, j;
      int minIndex = 0;
      int minValue;
      int temp;
      for (i = 0; i < a.length; i++) {
      minValue = a_;
      minIndex = i;
      for (j = i; j < a.length; j++) {

      if (a[j] < minValue) {
      minValue = a[j];
      minIndex = j;
      }
      }

      temp =a_;
      a_=a[minIndex];
      a[minIndex] = temp;

      }
      }

      }_~~~~

      1 Reply Last reply Reply Quote 0
      • Fire-Fist
        Fire-Fist
        last edited by
        Fire-Fist
        spiral
        Fire-Fist
        spiral

        should be in help desk

        …

        1 Reply Last reply Reply Quote 0
        • C
          Chicken
          last edited by
          C
          spiral
          Chicken
          spiral

          You are using print() instead of println(), that is why. Alternatively, you could use the newline escape sequence '\n'.

          1 Reply Last reply Reply Quote 0

          • 1 / 1
          • First post
            Last post
          Powered by NodeBB | Contributors