我正在尝试创建一个程序,它接受两个数字并输出一个数字中大于另一个数字的最小数字(例如,给定 4687 和 5,程序应该输出 6)。
我遇到的问题是,当我编译程序时,即使我没有收到错误,在输入两个数字后,也没有显示任何输出。光标只是继续在它所在的位置闪烁。这是代码:
import java.io.*;
import java.util.*;
public class Numbers {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
int smallest = 10;
int num;
System.out.printf("Enter a value for n: \n");
int n = in.nextInt();
System.out.printf("Enter a value for num: \n");
num = in.nextInt();
int ch = System.in.read();
while (ch>n && ch<smallest) {
smallest=ch;
ch = System.in.read();
}
System.out.printf("Smallest number that is larger is %d", smallest);
}
}