How many elements do you want in the array? 3 Enter an integer to store in the array 66 enter an integer to store in the array 33 enter an integer to store in the array 99 Here are the sorted values: [33,66,99]
This should be the result.
This is what I made:
import java.util.Scanner;
public class PracTe3Te {
/**
* @param args
*/
public static void main(String[] args) {
int [] a;
int size;
int value;
Scanner sc;
sc = new Scanner(System.in);
System.out.println("How many elements do you want in the array? ");
size = sc.nextInt();
a = new int [size];
System.out.println("the size of array is " + a.length);
for (int i = 0; i < a.length; i++)
{
System.out.println("Enter an integer to store in the array");
value = sc.nextInt();
a[i] = value;
int newNum = value;
if (value < a.length - 1) { //otherwise array is already full
a[value] = value;
newNum = newNum + 1;
}
}
System.out.print(a);
}
}
and get this result:
How many elements do you want in the array? 3 the size of array is 3 Enter an integer to store in the array 4 Enter an integer to store in the array 3 Enter an integer to store in the array 5 [I@60072ffb
How can I print the array list of entered items not like [I@60072ffb
?