import java.util.Scanner;
public class Question3 {
public static void main(String[] args) {
String input;
int i1,i2,i3;
Scanner keyboard = new Scanner(System.in);
System.out.println("Input a 3 digit number ");
input = keyboard.next();
String[] numbers = input.split("\\s+");
i1= Integer.parseInt(numbers[0]);
i2= Integer.parseInt(numbers[1]);
i3= Integer.parseInt(numbers[2]);
System.out.println(i1);
System.out.println(i2);
System.out.println(i3);
}
}
Here is what it should do: somebody types
1 2 3
and the program should output
1
2
3
however, it throws an arrayindexoutofbounds execpetion at the line i2= ….
I need them to be INTs btw because i need to do stuff with them afterwards… How can i fix this? (The question for my class is…)
Write a program that uses a Scanner to read three integers (positive) displays the biggest number of three. (Please complete without using either of the operators && or ||. These operators will be covered in class shortly. Similarly loops are not required.)
Some sample run:
Please input 3 integers: 5 8 3
The max of three is: 8
1 Answer