你给的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两周,脑子里乱七八糟没头绪。唉,真的不是这块料. ???????相信自己!!!
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两周,脑子里乱七八糟没头绪。唉,真的不是这块料.
???????相信自己!!!
推荐《Java2核心技术 卷1:基础知识》