/** 
 * NumericGame.java
 */
import java.io.*;
import java.math.*;public class NumericGame 
{
// Class constant
protected static final int timeNum = 8;
    protected static final int SelfIncrement = 1;
    protected static final int startMultipleNum = 2;
    protected static final int LineWidth = 80;
    
    // Class varibles
    protected static BigInteger num1, num2, result;
    
    // Class Functions
public static void main(String[] args) throws IOException 
{
BigInteger orgValue = Convert2BigInt("0");
     num2 = Convert2BigInt("2");
    
     try
     {
     if(args.length != 0)
     {
     num1 = Convert2BigInt(args[0]);
     }
     else
     {
     num1 = Convert2BigInt("0");
     System.out.println(
     "You have not specify a correct original number.");
     System.out.println(
     "Please input a number.");     // Get set up to read lines of text from the user
     String line = "";
        BufferedReader in = new BufferedReader(
         new InputStreamReader(System.in));
        
        for(;;) 
        {
line = in.readLine(); if (line.length() > 0)
                break;
else
return;
}    num1 = Convert2BigInt(line.toString());
     }
     if((num1.toString()).length() > 40)
     {
     System.out.println(
     "Sorry, you have inputted a number that has more than 40 digits.");
     return;
     }
    
     // record the original value of the user input.
     orgValue = num1;
     }
     catch(NumberFormatException ex)
     {
     System.out.println(
     "Sorry, cannot convert the inputted number into a number.");
     return;
     }     result = num1.multiply(num2);
     DoDataHandling();     if(result.compareTo(orgValue) == 0)
     {
     System.out.println("Operation correct.");
     }
     else
     {
     System.out.println("Operation Error.");
     }
     return;
    }
    
    protected static void DoDataHandling()
    {
     System.out.println(RightAlignPrint(String.valueOf(num1)));
     // out put the timed result
     for(int i = 0; i < timeNum; i ++) 
     {
     result = num1.multiply(num2);
     System.out.println(RightAlignPrint(num1 + " * " + num2));
     num1 = result;
     num2 = num2.add(Convert2BigInt(SelfIncrement));
     }
    
     num1 = result;
     num2 = Convert2BigInt(startMultipleNum);
    
     // out put the divided result
     for(int i = 0; i < timeNum; i ++) 
     {
     result = num1.divide(num2);
     System.out.println(RightAlignPrint(num1 + " / " + num2));
     num1 = result;
     num2 = num2.add(Convert2BigInt(SelfIncrement));
     }
     System.out.println(RightAlignPrint(String.valueOf(result)));
    }
    
    protected static BigInteger Convert2BigInt(int value)
    {
     return new BigInteger(String.valueOf(value));
    }
    
    protected static BigInteger Convert2BigInt(String value)
    {
     return new BigInteger(value);
    }
    
    protected static String RightAlignPrint(String str)
    {
     String preBlanks = "";
     for(int i = 0; i < (LineWidth - 1) - str.length(); i ++)
     {
     preBlanks += " ";
     }
     return preBlanks + str;
    }
}

解决方案 »

  1.   

    change
    new InputStreamReader(System.in);
    into
    new InputStreamReader(System.in, "ISO-8859-1");
      

  2.   

    谢谢tomuno(tomuno)。
    但是我按照您给的方法,还是会有这样的问题。现在我发现直接敲入Java也会有这样的问题。
    D:\Java\NumericGame>java
    WARNING: Default charset GBK not supported, using ISO-8859-1 instead
    Usage: java [-options] class [args...]
               (to execute a class)
       or  java -jar [-options] jarfile [args...]
               (to execute a jar file)
    ...