为什么我看不到我的项目在netbeans中运行?

时间:2020-09-24 23:42:55

标签: java netbeans

即使以前可以运行,我也无法使其正常运行。

import org.apache.commons.lang3.StringUtils;
import java.util.Scanner;
       

public class Main {

    static void bar_graph(int un, int deux, int trois, int quatre, int cinque) { //creates method bar_graph to take 5 integers and, for each integer, return that many asterisk
        
        int[] array = {un, deux, trois, quatre, cinque}; //creates array to hold the integers from bar_graph
        String graph = "*"; //creates string equal to *
        
        int counter = 0; //creates integer counter
        
        while(counter < 5){ //beginning of while loop which goes through the five integers in bar_graph and prints out, for each integer, that many asterisk
        String repeated = StringUtils.repeat(graph, array[counter]); //repeats the string graph as many times as the integer at array[counter] and equals it to a string called repeated
        System.out.println(repeated); //string repeated is printed
        counter++; //the counter increases by one
        }
    }
    
    public static void main(String[] args) {
        
        System.out.println("Emma Wilson - Programming Project 3 Exercise 4.16");
        
        Scanner graph = new Scanner(System.in);
        System.out.println("Please enter five integers between 1 and 30: "); //asks user to input five integers between 1 and 30
        
        int first = graph.nextInt(); //creates int first and equals it to first integer the user enters here
        while (first > 30 || first < 1){ //checks that the integer the user entered is between 1 and 30 and asks the user to enter an integer between 1 and 30 over and over
            System.out.println("That is not an integer between 1 and 30. Please enter an integer between 1 and 30: ");
            first = graph.nextInt();
        }
        
        int second = graph.nextInt(); //creates int second and equals it to next integer the user enters here
        while (second > 30 || second < 1){ //checks that the integer the user entered is between 1 and 30 and asks the user to enter an integer between 1 and 30 over and over
            System.out.println("That is not an integer between 1 and 30. Please enter an integer between 1 and 30: ");
            second = graph.nextInt();
        }
        
        int third = graph.nextInt(); //creates int third and equals it to next integer the user enters here
        while (third > 30 || third < 1){ //checks that the integer the user entered is between 1 and 30 and asks the user to enter an integer between 1 and 30 over and over
            System.out.println("That is not an integer between 1 and 30. Please enter an integer between 1 and 30: ");
            third = graph.nextInt();
        }
        
        int fourth = graph.nextInt(); //creates int fourth and equals it to next integer the user enters here
        while (fourth > 30 || fourth < 1){ //checks that the integer the user entered is between 1 and 30 and asks the user to enter an integer between 1 and 30 over and over
            System.out.println("That is not an integer between 1 and 30. Please enter an integer between 1 and 30: ");
            fourth = graph.nextInt();
        }
        
        int fifth = graph.nextInt(); //creates int fifth and equals it to next integer the user enters here
        while (fifth > 30 || fifth < 1){ 
            System.out.println("That is not an integer between 1 and 30. Please enter an integer between 1 and 30: ");
            fifth = graph.nextInt();
        }
        bar_graph(first, second, third, fourth, fifth); //calls method bar_graph
        
        
         
         
         }
}

代码截图1:

代码屏幕截图2:

代码运行屏幕截图3:

运行它时,netbeans不会显示我输入的整数或任何输出。

Netbeans运行另一个我正确编译的程序,但不是这个程序。

1 个答案:

答案 0 :(得分:0)

您尝试运行一个文件,但是最后一个文件而不是当前文件正在运行。

当使用main方法打开多个项目或具有多个文件并且在Netbeans中按“运行”(或按F6运行)时,会发生这种情况,并且它将运行您最后运行的文件。 / p>

将其视为“运行我的上次运行程序”之类的键。

如果要运行另一个文件,只需使用main方法打开文件,右键单击代码中的每个位置,然后按“运行文件”(或简单地按shift + F6的快捷键)

这样,您将告诉Netbeans不要运行我的上一个代码,而是运行此代码。

从现在开始,在IDE顶部的“运行”键运行此文件。除非您对其他文件执行相同的操作。