Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 显示过程已完成,但没有输出_Java_Jcreator - Fatal编程技术网

Java 显示过程已完成,但没有输出

Java 显示过程已完成,但没有输出,java,jcreator,Java,Jcreator,我正在尝试创建一个程序,该程序接受两个数字,并输出一个数字中大于另一个数字的最小数字(例如,给定4687和5,程序应输出6) 我遇到的问题是,当我编译程序时,即使我没有得到错误,在输入两个数字后,也没有显示输出。光标只是在它所在的位置继续闪烁。代码如下: import java.io.*; import java.util.*; public class Numbers { public static void main(String[] args) thro

我正在尝试创建一个程序,该程序接受两个数字,并输出一个数字中大于另一个数字的最小数字(例如,给定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);
}
}
import java.io.*;
导入java.util.*;
公共课号{
公共静态void main(字符串[]args)引发IOException{
扫描仪输入=新扫描仪(系统输入);
int=10;
int-num;
System.out.printf(“为n:\n输入一个值”);
int n=in.nextInt();
System.out.printf(“输入num:\n的值”);
num=in.nextInt();
int ch=System.in.read();

while(ch>n&&ch我很好地运行了您的程序。您所经历的可能只是程序正在等待您输入您不希望输入的内容

  • 它需要用户提供三个输入,是这样运行的吗
  • 输入数字后,你记得按键盘上的回车键吗
以下是您的程序的示例输出:

Enter a value for n: 
100
Enter a value for num: 
2
0 // <-- This value corresponds to your program prompting for int ch = System.in.read(); 
Smallest number that is larger is 10D

在这两个数字之后还有额外的读取。它不仅仅是在等待输入?您对
System.in.read()有什么期望
?我以为使用它会遍历变量num中的每个数字,但这就是我错的地方。我需要找到另一种方法,以某种方式使用循环遍历数字。哦,我认为我的问题在于逻辑。当我使用ch=System.in.read()时;我认为应该逐个遍历变量num中的每个字符,并在while循环中执行指令。我是否需要使用for循环或其他方法来遍历num中的每个数字?
for(char ch : Integer.toString(n).toCharArray()) { 
// rest of your while loop logic

}