……这么多。
如果只是单个知识点不明白,就问那知识点这样才会有人回答。像你这样直接给出那么多编程题让人做……我相信百人中有九十九人最多只做到前三题……!当然如果仅仅只是选择或填空或判断之类回答简易的话,还是可能会有人做的。
算了,给第一题答案你吧
一、public、extends、new。
public static void main(String[] args) {
//编程题1.1
paixu();
//编程题1.2
getSum();
//编程题2
copy();
//编程题3
read();
}
public static void paixu() {
int nums[] = new int[]{2,4,6,32,5345,124,25,356,345,0};
Arrays.sort(nums);
for(int tmp : nums){
System.out.println(tmp);
}
}
public static void getSum() {
double sum = 0;
int tmpfenmu = 1;
int tmpfenzi = 2;
int tmp;
String str = "";
for(int i=0;i<20;i++){
sum += tmpfenzi*1.0/tmpfenmu;
str += tmpfenzi + "/" + tmpfenmu;
if(i != 19){
str += "+";
}else{
str += "=";
}
tmp = tmpfenmu;
tmpfenmu = tmpfenzi;
tmpfenzi += tmp;
}
System.out.println(str + sum);
}
public static void copy() {
String filepath = "G:\\test\\my.txt";
try {
File file = new File(filepath);
BufferedReader buf = new BufferedReader(new FileReader(file));
String readtext = "";
String tmpread;
while ((tmpread = buf.readLine()) != null) {
readtext += tmpread + "\r\n";
}
buf.close();
// 除去结尾的\r\n
readtext = readtext.substring(0, readtext.length()-2);
filepath = "G:\\test\\text.txt";
file = new File(filepath);
BufferedWriter buw = new BufferedWriter(new FileWriter(file));
buw.write(readtext);
buw.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, e.toString(), "操作文件失败",JOptionPane.ERROR_MESSAGE);
}
}
public static void read() {
String filepath = "G:\\test\\text.txt";
try {
File file = new File(filepath);
BufferedReader buf = new BufferedReader(new FileReader(file));
String tmpread;
while ((tmpread = buf.readLine()) != null) {
System.out.println(tmpread);
}
buf.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, e.toString(), "操作文件失败",JOptionPane.ERROR_MESSAGE);
}
}
//编程题5
public class score {
// 私有成员变量english(英语分数)
private float english;
// 用来设置english的值
public void setScore(float english) {
this.english = english;
}
// 用来输出english的值
public void printScore(score stu){
System.out.println(stu.english);
}
public static void main(String[] args) {
score stu1 = new score();
stu1.setScore(85.5f);
stu1.printScore(stu1);
score stu2 = new score();
stu2.setScore(93.5f);
stu2.printScore(stu2);
}
}
其它的自己写吧……
为了拿你的分写了这么多……
都是基础题目,自己慢慢做就是,这种题目做好了对以后很有用的,做伸手党不好啊,主要是没人愿意费时间弄答案
1、public
9、extends
20、new
太多了,都是小程序,懒得做啊。。
晕倒!!!这样还学什么呢!