The content is the Java version of Last time (Python version). As for my impression, I like Python because it is simpler. Later, I felt the gratitude for the type being decided arbitrarily. The following code omits public ... etc., so only the main part is described.
The work itself of creating a variable called "input" and assigning it is done with ".nextLine ()".
simple.java
//Suppose the input data is
//5
Scanner input = new Scanner(System.in);//Define a variable that contains the input value
//Get
String l = input.nextLine();//Get as a string
//Or
int l = input.nextInt();//Get as an integer
Since Python ends with l = input (), I get the impression that it is quite sluggish ...
yoko1.java
//Suppose the input data is
//5 10 15
Scanner input = new Scanner(System.in);//Define a variable that contains the input value
String l = input.next();//Get as a string
//Or
int l = input.next();//Get as an integer
It's relatively easy to get just one. Rather, I feel that this is good for the one above.
yoko2.java
//Suppose the input data is
//5 10 15
Scanner input = new Scanner(System.in);//Define a variable that contains the input value
List<String> l = Arrays.asList(input.nextLine().split(" "));
//Get as a string. split("")Then you can take one character at a time, so it seems to be applicable.
//Or
???//Get as an integer
Utilize a variable list. One list is a lot of work ... The integer is unverified. (Scheduled to be added) I feel like I can use List
simple.java
//Suppose the input data is
//5
String l = new Scanner(System.in).nextLine();
//If you want to retrieve only one data, this is all. l=It becomes 5.
If you really want to retrieve only one piece of data, you can still read it. If you repeat the same syntax, an error will occur, so it seems that it can not be used very much for skill check of paiza.
[Java 8] Until converting standard input that can be used in coding tests into a list or array
Recommended Posts