环境: windowsxpsp2+jdk1.5.7(sun) classpath: C:\Program Files\Java\jre1.5.0_07\lib;C:\Program Files\Java\jre1.5.0_07\lib\tools.jar;C:\Program Files\Java\jre1.5.0_07\lib\dt.jar;C:\Program Files\Java\jre1.5.0_07\lib\tools.jar;C:\Program Files\Java\jre1.5.0_07\lib\rt.jar;. 目录结构: 保存在:"E:\onetwothree"下。 系统提示: Microsoft Windows XP [版本 5.1.2600] (C) 版权所有 1985-2001 Microsoft Corp.C:\Documents and Settings\ccyjava.MY-TOMATO>e:E:\>cd onetwothreeE:\onetwothree>javac Reader.javaE:\onetwothree>javac Ott.java Ott.java:22: 找不到符号 符号: 变量 Reader 位置: 类 onetwothree.Ott int a = Reader.getint(); ^ 1 错误E:\onetwothree> 文件具体内容: //Reader.java package onetwothree; import java.io.*; public class Reader { public static int getint()throws java.io.IOException{
String we = getString(); Integer me = Integer.valueOf(we); int a = me.intValue(); return a; } public static double getdouble()throws java.io.IOException{
String we = getString(); Double me = Double.valueOf(we); double a = me.doubleValue(); return a; } public static String getString()throws java.io.IOException{ BufferedReader io = new BufferedReader(new InputStreamReader(System.in)); String we = io.readLine(); return we; } } //Ott.java package onetwothree; class Ott { static int stone=21; static int winner=0;//this is kozi,0 means winner is PRO. public static void main(String[] args)throws java.io.IOException{ System.out.println("In the table,it has twenty-one stone.you can take up one,two or three stone."); System.out.println("The PRO is also,who take the last one,who win!"); while(stone != 0){ change_user(); if(stone != 0){ change_pro(); } } if(winner == 0){ System.out.println("The PRO is win!!!!!"); } else{ System.out.println("You win!!!!!,congrotelation to you!"); } } static void change_user()throws java.io.IOException{ int a = Reader.getint(); if(a>3||a<=0){ change_user(); }else{
if((stone - a)>=0){ stone = stone - a; System.out.println("you take up:"+a); if(stone == 0){ winner=1; } } else{ change_user(); } } } static void change_pro(){ int a = stone % 4; if (a==0){ int k =(int)((Math.random())*10); if(k<=4&&k>=0){ a=1; } else{ if(k>4&&k<=7){ a=2; } else{ a=3; } } stone = stone - a; System.out.println("The PRO take up:"+a); System.out.println("The stone is have:"+stone); } } } 情景画面: http://cn.pg.photos.yahoo.com/ph/csdnforever/detail?.dir=239c&.dnm=7b28cnb.jpg&.src=ph id:csdnforever password:csdncsdn
否则路径问题真的急死人~
书上有介绍,我没记清楚,我只是给你提示一下,呵呵。
注:我的classpath已按大家说的那样更改了。
windowsxpsp2+jdk1.5.7(sun)
classpath:
C:\Program Files\Java\jre1.5.0_07\lib;C:\Program Files\Java\jre1.5.0_07\lib\tools.jar;C:\Program Files\Java\jre1.5.0_07\lib\dt.jar;C:\Program Files\Java\jre1.5.0_07\lib\tools.jar;C:\Program Files\Java\jre1.5.0_07\lib\rt.jar;.
目录结构:
保存在:"E:\onetwothree"下。
系统提示:
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.C:\Documents and Settings\ccyjava.MY-TOMATO>e:E:\>cd onetwothreeE:\onetwothree>javac Reader.javaE:\onetwothree>javac Ott.java
Ott.java:22: 找不到符号
符号: 变量 Reader
位置: 类 onetwothree.Ott
int a = Reader.getint();
^
1 错误E:\onetwothree>
文件具体内容:
//Reader.java
package onetwothree;
import java.io.*;
public class Reader {
public static int getint()throws java.io.IOException{
String we = getString();
Integer me = Integer.valueOf(we);
int a = me.intValue();
return a;
}
public static double getdouble()throws java.io.IOException{
String we = getString();
Double me = Double.valueOf(we);
double a = me.doubleValue();
return a;
}
public static String getString()throws java.io.IOException{
BufferedReader io = new BufferedReader(new InputStreamReader(System.in));
String we = io.readLine();
return we;
}
}
//Ott.java
package onetwothree;
class Ott {
static int stone=21;
static int winner=0;//this is kozi,0 means winner is PRO.
public static void main(String[] args)throws java.io.IOException{
System.out.println("In the table,it has twenty-one stone.you can take up one,two or three stone.");
System.out.println("The PRO is also,who take the last one,who win!");
while(stone != 0){
change_user();
if(stone != 0){
change_pro();
}
}
if(winner == 0){
System.out.println("The PRO is win!!!!!");
}
else{
System.out.println("You win!!!!!,congrotelation to you!");
}
}
static void change_user()throws java.io.IOException{
int a = Reader.getint();
if(a>3||a<=0){
change_user();
}else{
if((stone - a)>=0){
stone = stone - a;
System.out.println("you take up:"+a);
if(stone == 0){
winner=1;
}
}
else{
change_user();
}
}
}
static void change_pro(){
int a = stone % 4;
if (a==0){
int k =(int)((Math.random())*10);
if(k<=4&&k>=0){
a=1;
}
else{
if(k>4&&k<=7){
a=2;
}
else{
a=3;
}
}
stone = stone - a;
System.out.println("The PRO take up:"+a);
System.out.println("The stone is have:"+stone);
}
}
}
情景画面:
http://cn.pg.photos.yahoo.com/ph/csdnforever/detail?.dir=239c&.dnm=7b28cnb.jpg&.src=ph
id:csdnforever
password:csdncsdn
javac -d . Reader.java;
javac -d . Ott.java;执行:
java onetwothree.Ott
JAVA会按照classpath里面设置的路径一个一个帮你找的··(记住用“;”)隔开。。
我用huihui0103() 提供的方法终于成功了,我用javac -cp . Ott.java或javac -cp E:\ Ott.java都成功了。
但是,为何直接用javac 不成功呢?它默认就是先在classpath后在所在的文件夹里找
类呀,为何还要指定途径?
我试着javac Reader.java后建了一个:"onetwothree" 文件夹,将Reader.class放进去,再javac
Ott.java 成功了!!谢谢大家,终于明白了!谢谢!谢谢!谢谢谢谢!马上要结贴了,给分了!!!