bufferedreader를 사용할 때 행을 건너 뛰고 사용자가 입력 한 내용을 읽습니다. System.out.print();와 같은 콘솔에서 행의 내용을 읽는 방법이 있습니까?java bufferedreader 다른 행 다음에 행을 읽지 않고 읽습니다.
예 : "여기 당신의 나이를 입력 :"
을 (여기 읽기) 대신 : "여기 당신의 나이를 입력 :"
가 '
내가 돈 (여기 읽기) 모든 문제에 대해 반드시 bufferedreader를 사용할 필요가 있습니다. 단지 줄 바꿈이 아닌 줄 바꿈을 읽고 싶습니다.
EDIT : 내가 깔아 놓은 프로그램의 코드입니다. 좋은 예입니다.
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
int y;
int z;
int x = 0;
String line2 = "empty";
String line = "empty";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br2 = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("enter 2 numbers of which the first is larger than the second");
try {
line = br.readLine();
}
catch (Exception e) {
e.printStackTrace();
}
try {
line2 = br2.readLine();
}
catch (Exception e) {
e.printStackTrace();
}
y = Integer.parseInt(line);
z = Integer.parseInt(line2);
if (y < 9 && y > 5 && z > 5 && z < 9) {
if (y > z) {
x = (int) ((Math.random() * (y - z)) + z);
}
if (z > y) {
x = (int) ((Math.random() * (z - y)) + y);
}
}else System.out.println("only numbers between 5 and 9!");
int[] getallen = new int[x];
for (int i = 0; i < x; i++) {
getallen[i] = (int) ((Math.random() * (y - z)) + z);
System.out.println(getallen[i]);
}
}
}
출력 :
"enter 2 numbers of which the first is larger than the second 2 5
only numbers between 5 and 9!"
변수 이름은 네덜란드에 있지만, 어쨌든 내 질문에 정말 관련이없는 : 내가 원하는
"enter 2 numbers of which the first is larger than the second
2
5
only numbers between 5 and 9!"
.
그것은 당신이 당신이 사용하는 정확한 코드를 게시 할 수 있다면 우리는 더 도움이 될 수 있습니다 내 시스템 (윈도우 7, JDK 1.8.0 25) – Atuos
에서 원하는 방식으로 작동합니다. –
@ isuru-buddhika 편집 – Arrrow