import java.io.*;
import javax.swing.JOptionPane;
public class one
{
public static void main(String[] args)
{
       System.out.println("请输入3个数:");
       double n[]=new double[3];
       double N=0;
       byte c[]=new byte[128];
       String str;
       try
       {
          for(int i=0;i<n.length;i++)
          {
          System.out.println("第"+(i+1)+"个数");       
          System.in.read(c);
          str=new String(c);
          n[i]=Double.parseDouble(str);
           }
        N=n[0];
        for(int i=1;i<n.length;i++)
        {
            if(n[i]>N)
              {
               N=n[i];
               }
         }
         }
         catch(IOException ioe)
         {
              System.err.println(ioe.toString());
         }
         System.out.println("最大值是:"+N)
         JOptionPane.showMessageDialog(null,"最大值是:"+N);      
}
}

解决方案 »

  1.   

    System.out.println("最大值是:"+N); //这里少个;号
    其它没发现问题
      

  2.   

    格式,变量命名方法有待改进.
    算法还可以优化一些.但是最后那个匿名调用JOptionPane的showMessageDialog方法用法不对,是不能实现的.
      

  3.   

    最后那个匿名调用JOptionPane的showMessageDialog方法用法没问题,可以编译/运行
    我试过了
      

  4.   

    试了下,原来是可以的,swing还能这样调对话框,汗!
    楼主要注意类名大写,注意缩进,还有parse的转换异常没有catch。
      

  5.   

    System.in.read(c); 有问题,
    这将使得以前读的数据未清空就在原内存地址直接写了进去.所以会有异常出现你在此处添加一句即可知道:
    ...     ...
    System.in.read(c);
    str=new String(c);
    System.out.println(str);  // 添加此句
    ...     ...
    对策:
    更改程序:
    for(int i=0;i<n.length;i++)
    {
         System.out.println("第"+(i+1)+"个数");       
         System.in.read(c);
         str=new String(c);
         System.out.println(str);
         n[i]=Double.parseDouble(str);
    }为:
    for(int i=0;i<n.length;i++)
    {
        System.out.println("第"+(i+1)+"个数");       
        str= new BufferedReader(new InputStreamReader(System.in)).readLine();
        n[i]=Double.parseDouble(str);
    }
      

  6.   

    对于刚才说的异常,你可以输入
    第一个数:12345
    第二个数:1即可知
    F:\>java one
    请输入3个数:
    第1个数
    12345
    获得到的数是:12345第2个数
    1
    获得到的数是:1
    45Exception in thread "main" java.lang.NumberFormatException: For input string: "45"
            at java.lang.NumberFormatException.forInputString(NumberFormatException
      

  7.   

    JOptionPane的方法不行,另外读数的过程太复杂了
      

  8.   

    把程序:
    for(int i=0;i<n.length;i++)
    {
         System.out.println("第"+(i+1)+"个数");       
         System.in.read(c);
         str=new String(c);
         System.out.println(str);
         n[i]=Double.parseDouble(str);
    }更改为:
    for(int i=0;i<n.length;i++)
    {
        System.out.println("第"+(i+1)+"个数");       
        int len=System.in.read(c);
        str=new String(c,0,len);
        n[i]=Double.parseDouble(str);
    }
    也可以解决这种异常。但楼上的似乎更好些。
    另外,也可以让这个程序更完善,解决其输入不是数字的问题:
    import java.io.*;
    import javax.swing.JOptionPane;
    public class One
    {
    public static void main(String[] args)
    {
           System.out.println("请输入3个数:");
           double n[]=new double[3];
           double N=0;
           byte c[]=new byte[128];
           String str;
          
           
           
           try
            { 
              for(int i=0;i<n.length;i++)
              {
               System.out.println("第"+(i+1)+"个数:"); 
                  
               int len= System.in.read(c);
             
             
               str=new String(c,0,len);
              //System.out.println(str);
               try
               {
                    n[i]=Double.parseDouble(str);
                        }
               catch(Exception e)
               {
                    System.out.println("您没有输入数字!");
                    i--;
                    
               }
              
              
              }
            }
            catch(IOException ioe)
              {
               
                 System.err.println(ioe.toString());
               }
            N=n[0];
            for(int i=1;i<n.length;i++)
            {
                if(n[i]>N)
                  {
                   N=n[i];
                   }
             }
             
            
             System.out.println("最大值是:"+N);
             JOptionPane.showMessageDialog(null,"最大值是:"+N);      
    }
    }
      

  9.   

    现在居然还有人用这样老套的东西.来输入数据.
    I full you!