Please forgive it as it will be a self-sufficient memorandum.
class Hello {
public static void main(String[] args) {
System.out.println("hello IKEMEN");
}
}
↓
Terminal
hello IKEMEN
The character string enclosed in "" is displayed.
class Hello {
public static void main(String[] args) {
String name = "IKEMEN"
System.out.println("hello" + name);
}
}
↓
Terminal
helloIKEMEN
There is no margin as it is, so I will correct it.
class Hello {
public static void main(String[] args) {
String name = "IKEMEN"
System.out.println("hello " + name);
}
}
Put a margin after hello in System.out.println ("hello" + name) ;. ↓
Terminal
hello IKEMEN
There is a margin and it is beautiful.
import java.util.Scanner;
class Hello {
public static void main(String[] args) {
System.out.print("Your name? ");
String name = new Scanner(System.in).next();
System.out.println("hello " + name);
}
}
It seems that new Scanner (System.in) .next (); can receive input from the keyboard. ↓
Terminal
Your name?
Is displayed, so type in the character string (IKEMEN) ↓
Terminal
Your name? IKEMEN
hello IKEMEN
import java.util.Scanner;
class Hello {
public static void main(String[] args) {
System.out.print("Your guess? ");
Integer guess = new Scanner(System.in).nextInt();
System.out.println("Your guess: " + guess);
}
}
It seems that new Scanner (System.in) .nextInt (); receives the input value as an integer. ↓
Terminal
Your guess?
Is displayed, so enter the numerical value (6). ↓
Terminal
Your guess? 6
Your guess: 6
import java.util.Scanner;
class Hello {
public static void main(String[] args) {
Integer answer = 6;
System.out.print("Your guess? ");
Integer guess = new Scanner(System.in).nextInt();
if (answer == guess) {
System.out.println("Correct answer!");
} else {
System.out.print("Lost");
}
}
}
If the entered number is 6, it will be displayed as correct! If it is not 6, it will be displayed as lost.
import java.util.Scanner;
class Hello {
public static void main(String[] args) {
Integer answer = 6;
System.out.print("Your guess? ");
Integer guess = new Scanner(System.in).nextInt();
if (answer == guess) {
System.out.println("Correct answer!");
} else if (answer > guess) {
System.out.println("Larger");
} else {
System.out.println("Smaller");
}
}
}
If the number you entered is 6, it will be displayed as correct !, if it is less than 6, it will be displayed as larger, and if it is greater than 6, it will be displayed as smaller.
Recommended Posts