使用JAVA.IO中,创建一个文档,向其中写入数据遇到问题,
编码如下:importjava.io.*;publicclassNarcissus{publicstaticvoidmain(String[]args)throwsIOE...
编码如下:
import java.io.*;
public class Narcissus
{
public static void main (String[] args)throws IOException{
String outfilename="test.txt";
File fout =new File(outfilename);
PrintWriter out=new PrintWriter(new FileWriter(fout));
int i,j,k,n=100,m=1;
while(n<1000)
{
i=n/100;
j=n/10%10;
k=n%10;
if(i*i*i+j*j*j+k*k*k==n){
out.println("第"+ m +"水仙花数: "+n+"\\n");}
m++;n++;
}
}
}
编码没出错,结果就是文档里空空的,写不进数据. 展开
import java.io.*;
public class Narcissus
{
public static void main (String[] args)throws IOException{
String outfilename="test.txt";
File fout =new File(outfilename);
PrintWriter out=new PrintWriter(new FileWriter(fout));
int i,j,k,n=100,m=1;
while(n<1000)
{
i=n/100;
j=n/10%10;
k=n%10;
if(i*i*i+j*j*j+k*k*k==n){
out.println("第"+ m +"水仙花数: "+n+"\\n");}
m++;n++;
}
}
}
编码没出错,结果就是文档里空空的,写不进数据. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询