포스트

[Java] Baekjun number 10926 - ??!

We have summarized how to receive string input in Java and output characters that match the conditions.

한국어 원문은 여기에서 볼 수 있습니다.
[Java] Baekjun number 10926 - ??!

BaekJoon 10926

Solution

1
2
3
4
5
6
7
8
9
10
11
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        
        String name = input.next();
        
        System.out.printf(name + "??!");
    }
}

Strings in Java

  • Receive string input using String class

Difference between next() and nextLine()

  • When inputting a string in Java, input can be received through .next() and .nextLine() from the String class. .next(): Receives input of characters or strings one by one, one word or one character at a time.
    • ex) If you enter Hello World!, only Hello will be entered. .nextLine(): Receives input of characters or the entire sentence before hitting enter.
    • ex) If you enter Hello World!, the entire Hello World! will be entered.