0

I have to create 3 arrays and prompt the user for a number that is greater than 100 that will serve as the size for all 3 arrays. Then I have to generate that amount of random numbers to fill these arrays ranging from 1-99. So far I have this:

public static void main(String [] args){
    Scanner SC = new Scanner(System.in);
    System.out.println("Enter size of array:");
    int size = SC.newInt();

I am fairly new to programming, I'm really just trying to learn and I cant seem to figure this out.

2
  • newInt()? Do you mean nextInt()? Once you've got that right, add a closing bracket at the end and see if it will compile. Put in System.out.println(size) at the end to see if it prints out the number you entered, compile again, and run. Then try to allocate the arrays, try to compile again. Fill them with 0's or 1's and try to print. Etc. Commented Apr 11, 2015 at 20:24
  • Sorry about that. Yes, I meant to write nextInt(). Thank you. I will give that a try! Commented Apr 11, 2015 at 21:47

2 Answers 2

1

Firstly SC.newInt(); should be SC.nextInt();;

You can create integer array with 100 elements this way:

int[] array = new int[100];

You can generate random integer number from 1 to 99 this way:

Random rand = new Random();  
rand.nextInt((max - min) + 1) + min; // max = 99, min = 1 in your case
Sign up to request clarification or add additional context in comments.

Comments

0

Hope this helps:

Scanner s = new Scanner(System.in);
int size = s.nextInt();
if(size < 100) {
    System.out.println("Size not enought");
    return;
}
int arr1[] = new int[size];
int arr2[] = new int[size];
int arr3[] = new int[size];
for(int i = 0;i < size; i++) {
    int value = (int)(Math.ceil(Math.random() * 99));
    arr1[i] = value;
    value = (int)(Math.ceil(Math.random() * 99));
    arr2[i] = value;
    value = (int)(Math.ceil(Math.random() * 99));
    arr3[i] = value;
    System.out.println(arr1[i] + " " + arr2[i] + " " + arr3[i]);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.