Topic: 文件编译不成功,是什么原因?

  Print this page

1.文件编译不成功,是什么原因? Copy to clipboard
Posted by: lpclpc123
Posted on: 2005-10-17 20:18

出错信息:can not read PrimeNumber.java

import java.io.*;

class PrimeNumber {
  public static void main(String[] args) {
    int num=0;
    boolean flag=true;
    try{
      do{
        System.out.println("请输入一个正整数:");
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        num=Integer.parseInt(br.readLine());
      }while(num<0);
    }catch(IOException e){}
    
    for(int i=2;i<=(int)Math.sqrt(num);i++){
      if(num%i==0){
        flag=false;
        break;
      }
    }
      
    if(flag&&num!=1)
      System.out.println("您输入的数:"+num+"是一个素数");
    else
      System.out.println("您输入的数:"+num+"不是一个素数");
  }
}

2.Re:文件编译不成功,是什么原因? [Re: lpclpc123] Copy to clipboard
Posted by: bluecrystal
Posted on: 2005-10-17 21:17

不明白,我这里编译成功了的
请看执行结果:

D:\temp>java PrimeNumber
请输入一个正整数:
34343340
您输入的数:34343340不是一个素数

3.Re:文件编译不成功,是什么原因? [Re: lpclpc123] Copy to clipboard
Posted by: lpclpc123
Posted on: 2005-10-18 09:23

路径设置应该没问题把,我运行其他文件都没问题啊,不知道那里出错了

4.Re:文件编译不成功,是什么原因? [Re: lpclpc123] Copy to clipboard
Posted by: why
Posted on: 2005-10-18 10:03

Read [加贴须知] http://www.cjsdn.net/post/view?bid=1&id=119201
and show us
> echo %JAVA_HOME%
> echo %PATH%
> echo %CLASSPATH%
> rem X is the drive letter where the java source is
> X:
> rem YourFolder is the folder where the java source PrimeNumber.java is
> cd YourFolder
> dir
> javac PrimeNumber.java
> java PrimeNumber

5.问题找到了,谢谢! [Re: lpclpc123] Copy to clipboard
Posted by: lpclpc123
Posted on: 2005-10-18 15:23

C:\Documents and Settings\hypking>echo %JAVA_HOME%
C:\j2sdk1.4.1_07

C:\Documents and Settings\hypking>echo %PATH%
C:\j2sdk1.4.1_07\bin;C:\Program Files\IDM Computer Solutions\UltraEdit-32

C:\Documents and Settings\hypking>echo %CLASSPATH%
C:\j2sdk1.4.1_07\lib\tools.jar;C:\j2sdk1.4.1_07\jre\lib\rt.jar;

E:\java>dir
2003-10-05 15:41 641 PrimeNumber .java.bak
原来问题在这里,(.java.bak),这是什么格式啊?改成.java就可以运行了.
谢谢了!

6.Re:文件编译不成功,是什么原因? [Re: lpclpc123] Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-10-27 14:55

用EditPlus 2写程序或修改的时候 它会自动的有的先前代码的备份。(.java.bak)

7.Re:文件编译不成功,是什么原因? [Re: lpclpc123] Copy to clipboard
Posted by: witer666
Posted on: 2005-11-05 12:22

你保存的不是以JAVA为扩展名的文件,就会出现can not read!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923