| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1539 人关注过本帖
标题:一些很简单的题目
只看楼主 加入收藏
myfor
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:357
专家分:6
注 册:2006-3-13
收藏
得分:0 
以下是引用渐渐成为高手在2007-6-28 10:22:29的发言:
//1-20的阶乘
class Factorial
{
void fn()
{
int i=1;j=1;
long sum=0;
for(i=1;i<=20;i++)
{
j=*i;
sum=+j;
}
System.out.println(sum);
try
{
if(sum>1000)
System.out.println("Exception");
}
catch(Exception e)
{
System.out.println(sum);
}
}
}
class Test
{
public static void main(String[] args)
{
Factorial f=new Factoral();
f.fn();
}
}

不对


广告位招租
2007-06-29 23:19
huozoo
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-6-28
收藏
得分:0 

我最痛恨的是什么,就是程序都没在电脑上运行过,看了题目有点头绪就以为自己肯定能写出程序来的人。
学编程语言必须:看书!-> 看程序!-> 写程序!-> 出错要会改程序!
看书懂不代表你就会写```总之你要想掌握这门语言必须学会写代码,不断写```

2007-06-30 10:19
xuxianyue123
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2007-6-9
收藏
得分:0 
支持楼上的,看程序跟写程序天壤之别啊。
2007-06-30 10:52
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 

晕死
我敲了
第三题有点问题!
//利用FileInputStream和FileOutputSteam编写一个文件拷贝的程序
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.*;
import java.nio.channels.FileChannel;
class Copy
{
String filename = null;
String path = "456";
File file =null;
String objFilename = null;
File objfile = null;
FileOutputStream output = null;
FileInputStream input = null;
FileChannel inputchannel = null;
FileChannel outputchannel = null;
File pathfile=null;
File yuanfile = null;
File bojectfile = null;
Copy(String yuan,String obj)
{
pathfile = new File(path);
yuanfile = new File(yuan);
bojectfile = new File(obj);
filename = yuan;
objFilename = obj;
file = new File(path,filename);
objfile = new File(path,objFilename);
judge(pathfile,file);
judge(pathfile,objfile);
read();
write();
}
public void judge(File pathfile,File file) //判确定文件存在
{
if(pathfile.isDirectory()==false)
{
pathfile.mkdirs();
}
if(file.isFile()==false)
{
try
{
file.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
public void read() //读文件
{
try
{
input = new FileInputStream(file);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
ByteBuffer buf = ByteBuffer.allocate(200);
inputchannel = input.getChannel();
try
{
inputchannel.read(buf);
}
catch (IOException e)
{
System.out.println(e.toString());
}
buf.flip();
System.out.println("文件内容:");
//System.out.println(buf.get());
try //关闭流
{
input.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void write() //写文件
{
try
{
output = new FileOutputStream(objfile);
}
catch (FileNotFoundException e1)
{
e1.printStackTrace();
}
ByteBuffer buf = ByteBuffer.allocate(200);
outputchannel = output.getChannel();
try
{
inputchannel.write(buf);
}
catch (IOException e)
{
System.out.println(e.toString());
}
buf.flip();
System.out.println("文件写入完成");
try
{
output.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public String toString()
{
return "完成";
}
public static void main(String args[]) //主方法
{
String yuan="123.txt";
String obj="456.txt";
Copy copy = new Copy(yuan,obj);
//System.out.println(copy.toString());
}
}


骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2007-06-30 11:36
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 
看看,一个代码就这么长!~~
大家给我看看,结果有点问题!

骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2007-06-30 11:37
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
你不写,永远不会进步

可惜不是你,陪我到最后
2007-06-30 11:51
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 
以下是引用千里冰封在2007-6-30 11:51:54的发言:
你不写,永远不会进步

谁说我没写
能帮我看看错哪了吗?!


骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2007-06-30 11:57
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 

写了就好,写了别人才好帮你,


可惜不是你,陪我到最后
2007-06-30 11:58
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
你用NIO?

用IO不就可以了

可惜不是你,陪我到最后
2007-06-30 12:00
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 
其实我很多都写过
这回是帮别人做
自己写太累了
我写了前4题
要是谁给我点想法也好,写的头都疼

骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2007-06-30 12:00
快速回复:一些很简单的题目
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017113 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved