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);
}
}
下面是它應該做的:某人類型和程序應輸出分割字符串轉換成3份和轉換爲int
3然而,它會在行i2 = ...處引發一個arrayindexoutofbounds execpetion。...
我需要它們爲INT順便說一句,因爲我需要與他們之後做的東西...我怎樣才能解決這個問題? (我的課的問題是...)
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 2 3不是123 謝謝 – Killerpixler
您可以爲自己定義分隔模式。 –