I'm trying to write a program that meets the following requirements. I'm getting all kinds of errors because I'm a noob but I'm trying to learn! Please help.
1. Create an array with 100 randomly chosen integers.
2. Prompt the user to enter the index of the array, then display the corresponding element value. If the specified index is out of bounds, display the message "Out of Bounds."
1. Create an array with 100 randomly chosen integers.
2. Prompt the user to enter the index of the array, then display the corresponding element value. If the specified index is out of bounds, display the message "Out of Bounds."
Code:
import java.util.Scanner;
import java.io.*;
public class exceptionHandling {
public static void main(String[] args) {
//create random number between 1 to 100
Random rn = new Random();
int r = rn.nextInt(100)+1;
Scanner scan = new Scanner(System.in);
//prompt user to enter a random number
System.out.print("Enter an integer: ");
int index = scan.nextInt();
if (index > r.length)
System.out.println("Out of Bounds.");
}
}