日期:2014-05-20  浏览次数:20717 次

笨笨的程序求救....!!
import   java.io.*;
import   java.lang.Number;
import   java.lang.Math;  

public   class   guess
{
public   static   void   main(String   []   args)
{
try{
//boolean   flag   =   false;
while(true)
{
System.out.println( "Please   enter   a   number: ");
BufferedReader   read   =   new   BufferedReader(new   InputStreamReader(System.in));
String   num   =   read.readLine();
String[]   str   =   new   String();                   //这里报错
for(   int   i   =   0;   i   <=   num.length();   i++)
{
if   (   str[i]   >   'a '   &&   str[i]   <   'z '   )                 //这里报错
{
System.out.println( "Entered   Wrongly ");
System.out.println( "Please   enter   again ");
continue;
}
}
int   b   =   Integer.parseInt(num);
if   (   b   <   0   ||   b   > 99   )
{
System.out.println( "Entered   Wrongly! ");
System.out.println( "Please   enter   again ");
continue;
}

double   s   =   Math.random()   *   100;
if   (b   >   s)
{
System.out.println( "large ");
}
else   if   (   b   <   s)
{
System.out.println( "Small ");
}
else
{
System.out.println( "equal ");
}

}

        }
catch(IOException   e){}
}
}


请高手帮我看看啊,我找了半天也没有找到原因

------解决方案--------------------
你是不是想这样啊?


import java.io.*;
import java.lang.Number;
import java.lang.Math;

public class guess {
public static void main(String[] args) {
try {
//boolean flag = false;
outer: while (true) {
System.out.println( "Please enter a number: ");
BufferedReader read = new BufferedReader(new InputStreamReader(
System.in));
String num = read.readLine();
// String[] str = new String[num.length()]; //这里报错
for (int i = 0; i < num.length(); i++) {
if (Character.isDigit(num.charAt(i))==false) { //这里报错
System.out.println( "Entered Wrongly ");
System.out.println( "Please enter again ");
continue outer;
}
}
int b = Integer.parseInt(num);
if (b < 0 || b > 99) {
System.out.println( "Entered Wrongly! ");
System.out.println( "Please enter again ");
continue;
}

double s = Math.random() * 100;
if (b > s) {
System.out.println( "large ");
} else if (b < s) {
System.out.println( "Small ");
} else {