System.in取外部输入的数据.逻辑要自己判断罗

解决方案 »

  1.   

    你给的fraction class 有一个错误!
    public String toString()
    {
        return (“” + iNum + “/” + iDen);
     }
    标点符号有误,应为:
        return ("" + iNum + "/" + iDen);
     下给出Test class:import java.io.*;
    public class test 
      {
      public static void main( String args[] )throws Exception
    {   
        
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String strN = null;
    String strD = null;
    //String[] s= new String[5];
    for (int i=1;i<6; i++)
    {
      System.out.println("Pls input a number as  numerator:");
      System.out.flush();
      strN = br.readLine();
      System.out.println("Pls input a number as denominator:");
      System.out.flush();
      strD = br.readLine();
      try
      {  
       fraction frac = new fraction(Integer.parseInt(strN.trim()),
       Integer.parseInt(strD.trim()));
     System.out.print("you have input the "+i+" molecular formula is:");
         frac.output();
         System.out.println(); 
         System.out.println();
      }
      catch(NumberFormatException ne)
     {
    System.out.println("you have input "+ ne.getMessage()+" is not a number! ");
    i--;
     }
      
    }    
    System.exit(0);  // ends the program
    } // end main method  } // end class test另:
    我学JAVA两周,脑子里乱七八糟没头绪。唉,真的不是这块料.
    ???????相信自己!!!
      

  2.   

    建议你买一两本有多一点例子的书看看,动手做做上面的例子,不久你会发现你也是一位JAVA高手!
    推荐《Java2核心技术  卷1:基础知识》