【问题标题】:nothing will output什么都不会输出
【发布时间】:2013-01-31 13:50:35
【问题描述】:

无论我将输出语句放在哪里,无论是数组的1个位置,数组的所有位置,甚至是计数变量。我无法将任何内容打印到控制台。我已经尝试在主要和功能中打印。有什么想法吗?

Edit1:我发现我可以在 jswing 窗口中打印,但控制台仍然没有运气,这使得错误检查变得困难。

鉴于我仍然可以在窗口中正确输出,并且人们声称 eclipse 会打印出来,我认为我的古代文本编辑器的控制台是无能的,我感谢帮助 '

//=========================//
//colby moniz project 9-1  //
//Number sorter            //
//=========================//

//===========================================//
//This program takes 10 integers and sorts   //
//them into even, odd, and negative.         //
//===========================================//

//=============//
//Import Files //
//=============//
import javax.swing.*;       // DRAW DIALOG BOX CLASS
import java.awt.*;          // IMPORT AWT TO CHANGE FONT AND COLORS




public class p91 {


    public static void main(String[] args) {


        //=================================//
        //varbiles section                 //
        //=================================//
        sorter sort = new sorter();   //Creatests an instances of sorter, inside main.
        int[] test = new int[10];
        int inputNum;

        //================================//
        //Introduction windows            //
        //================================//    
        info( "This program will sort 10 intergers, \n into the catagories minimum, maximum and negitive",
        "Introduction" );
        //===========================//
        //fill up array              //
        //===========================//
        for(int count = 0; count < 10; count++)
        {
            inputNum = input("please input number " + (count + 1), "Input");
            test[count] = inputNum;
        }   




        for(int count = 0; count < 10; count++)
        {
          System.out.print(test[count]);    
        }


    }





//====================================================//
//Functions                                           //
//====================================================//    


        public static void info(String a, String b)
    {
           //================================//
           //Introduction window             //
           //================================//
            int close = JOptionPane.showConfirmDialog(null,
                                a, b,                                      
                                JOptionPane.DEFAULT_OPTION, 
                                JOptionPane.INFORMATION_MESSAGE); 

            checkCloseInt(close); 
    }

        public static void checkCloseInt(int close)
    {
            //=====================================
            //checks to see if user closed program 
            //=====================================                 
            if ((close == JOptionPane.CLOSED_OPTION) || 
                (close == JOptionPane.NO_OPTION)  ||
                 (close == JOptionPane.CANCEL_OPTION))          
                 System.exit(0);       
    }

        public static int input(String a, String b)
    {
           //================================//
           //input                           //
           //================================//
            boolean parsable;
            int inputParse = 999;
            String input;

           do
           {           
                     input = JOptionPane.showInputDialog(null,
                                        a, b,                                      
                                       JOptionPane.QUESTION_MESSAGE); 

                    //======================//
                    //Check if close        //
                    //======================//
                        if(input == null)
                        {
                            System.exit(0);
                        }

                    parsable = error(input);

           }
           while(parsable == false);

        inputParse = Integer.parseInt(input);  
                    System.out.print(inputParse); 
        return inputParse; 
    }



    public static boolean error(String input)
    {
         //======================
         //Check if parsable
         //=======================
         boolean parsable = true;
          try
          { 
            int inputParse = Integer.parseInt(input);
          }
          catch(NumberFormatException e)
          {
           parsable = false;
          } 

          if(parsable == false)
          {
                    errorWindow("Please input a number");
          } 

          return parsable; 



    }

        public static void errorWindow(String a)
    {
           //================================//
           //Introduction window             //
           //================================//
            int close = JOptionPane.showConfirmDialog(null,
                                a, "Error",                                    
                                JOptionPane.DEFAULT_OPTION, 
                                JOptionPane.ERROR_MESSAGE); 

            checkCloseInt(close); 
    }




}

'

【问题讨论】:

  • 我在 Eclipse 中执行了您的代码。输入 10 个数字后,我检查了控制台,它们就在那里!之前输入的 10 个号码!更不用说执行System.out.print(inputParse)的结果了……你需要提供更多细节……

标签: java arrays printing for-loop output


【解决方案1】:

使用System.out.println(); 这对我有用。

【讨论】:

  • Log.e(String, String) 仅适用于 android 而不是简单的 java 应用程序
  • 我试过 println,什么也没发生。如果有帮助,在每个输入窗口之后它会闪烁,然后再进入下一个。
猜你喜欢
  • 1970-01-01
  • 2013-02-07
  • 2012-10-12
  • 1970-01-01
  • 1970-01-01
  • 2019-02-27
  • 1970-01-01
  • 2022-07-27
  • 1970-01-01
相关资源
最近更新 更多