我使用Java在NetBeans IDE中编写了一个简单的程序。今天早上对主方法进行了一些更改后,控制台在运行程序时不会打印任何内容。我只想让它达到startMenus(sc)。编辑:我现在已经放入一些System.out.println()并且它没有到达" Blah2"这是我第一次循环后......
public class Calculator {
public static int[] NUMBERS; //global value for the array
public static void main(String[] args) throws FileNotFoundException {
File file = new File("data.txt");
Scanner sc = new Scanner(file);
System.out.println("Blah1");
int counter = 0;
while (sc.hasNextInt()) {
counter = counter++;
}
System.out.println("Blah2");
int lenth = counter;
NUMBERS = new int[lenth];
System.out.println("Blah3");
sc.close();
File file2 = new File("data.txt");
Scanner sc2 = new Scanner(file2);
System.out.println("Blah4");
int i = 0;
while (sc2.hasNextInt()) {
NUMBERS[i] = sc2.nextInt();
++i;
}
System.out.println("Blah5");
sc2.close();
System.out.println("Welcome to Calculation Program!\n");
startMenus(sc);
}
}
答案 0 :(得分:0)
你确定在它到达System.out.println之前你没有抛出任何杀死你的app的异常吗?根据您的描述判断,您可能希望调试或将其他一些println语句放在链中,因为它可能因某些原因而死亡。
答案 1 :(得分:0)
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Calculator {
public static int[] NUMBERS; //global value for the array
public static void main(String[] args) throws FileNotFoundException, IOException {
File file = new File("data.txt");
file.createNewFile();
Scanner sc = new Scanner(file);
int counter = 0;
while (sc.hasNextInt()) {
counter = counter++;
}
int lenth = counter;
NUMBERS = new int[lenth];
sc.close();
File file2 = new File("data.txt");
file2.createNewFile();
Scanner sc2 = new Scanner(file2);
int i = 0;
while (sc2.hasNextInt()) {
NUMBERS[i] = sc2.nextInt();
++i;
}
sc2.close();
System.out.println("Welcome to Calculation Program!\n");
startMenus(sc);
}
private static void startMenus(Scanner sc) {
System.out.println("Run your code here!!!");
}
}
一些事情:
我已经包含了一些更正的代码。希望这有帮助!
答案 2 :(得分:0)
System.out调用可能尚未到达,因为你的一个循环执行时间太长,你愿意等待的时间更长。从循环内部记录一些东西以获得更多反馈,程序可能很好。