import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
//sc.nextLine();
System.out.println(a);
String s = sc.nextLine();
System.out.println(s);
}
}
nextInt는 엔터를 버퍼에 남기기 때문에
다음에 s를 입력하기 전에 엔터가 남아있어서
공백이 출련된다.
이것을 수정하기 위해
sc.nextLine()을 사용하면
엔터의 버퍼를 지워주기 때문에
다음 문자를 입력할 수 있다.
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
sc.nextLine();
System.out.println(a);
String s = sc.nextLine();
System.out.println(s);
}
}
숫자만 입력 두번 할 시
nextLine()이 필요없다.
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
//sc.nextLine();
System.out.println(a);
int s = sc.nextInt();
System.out.println(s);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String before = sc.next();
System.out.println(before);
int after = Integer.parseInt(before.substring(0,2));
System.out.println(after);
}
}
Integer.parseInt()는 문자열(String) 로 되어 있는 숫자를 정수(int) 로 바꿔주는 함수
package SWEA;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] arr = new int[N];
for(int i = 0; i < N; i++){
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
int midIndex = N/2;
System.out.println(arr[midIndex]);
}
}
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger n = sc.nextBigInteger();
BigInteger m = sc.nextBigInteger();
System.out.println(n.divide(m));
System.out.println(n.remainder(m));
sc.close();
}
}