这是我在运行java代码进行清理和格式化的NetBeans上的第一个任务。我没有任何其他编程语言的经验。在我运行该文件后,它永远不会结束运行。我不知道要寻找什么。我尝试了一些建议,包括灯泡旁边的灯泡,但没有奏效。 (*代码已给出且未更改)带输入/输出的Java程序没有完成运行(挂起)
import java.util.Scanner;
public class InputOutput {
public static void main(String[] args) {
/* Using print statements */
System.out.println("Print first ");
System.out.println("Print second ");
/* Using println statements */
System.out.println("Print third");
System.out.println("Print fourth");
System.out.println("Print fifth");
/* Create a scanner for inputs */
Scanner input = new Scanner(System.in);
/* Get the color and display it */
System.out.println("What is your favorite color?");
String color = input.nextLine();
System.out.println("You wrote: " + color);
/* Get the num of apples and display */
System.out.println("How many apples do you have?");
int numApples = input.nextInt();
System.out.println("You wrote: " + numApples);
/* Close the scanner */
input.close();
}
}
你怎么知道它“永不结束”?我跑你的代码,并终止罚款。 –
请显示输入/输出**编辑**对我来说工作正常 –
也许你应该在你的代码的最后添加一条消息,打印一条消息说明程序已经完成。 –