用JAVA语言编写一个程序,要求如下:

帮忙用java基础语言编写一个程序 要求如下~

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.List;

public class QuestionOne {
/**
* 打开一个文本文件,每次读取一行内容。将每行作为一个String读入,
* 并将那个String对象置入一个Linkedlist中。按相反的顺序打印出Linkedlist中所有的行。
* 同样也打开一个文本文件,以便将文本写入其中。将Linkedlist中的各行随同行号一起写入文件。 很急 请高手帮帮忙啊。!!!!!!!!!!!!!
*
* @throws IOException
*/
public static void main(String[] args) {
String inputFilePath = "c:/c.txt";
String outputFilePath = "c:/output.txt";

File inputFile = new File(inputFilePath);

if (!inputFile.exists()) {
System.out.println("输入文件不存在:" + inputFilePath);
return;
}
List strs = new LinkedList();

// 读取文件中的内容到List中
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(inputFile)));
String lineString = null;
while ((lineString = reader.readLine()) != null) {
strs.add(lineString);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("输入文件不存在:" + inputFilePath);
return;
} catch (IOException e) {
e.printStackTrace();
return;
}

// 逆向输出
System.out.println("逆向**start***");
for (int i = strs.size() - 1; i >= 0; i--) {
System.out.println(strs.get(i));
}
System.out.println("逆向**end***");
try {
PrintWriter writer = new PrintWriter(outputFilePath);
// 输出到文件
for (int i = 0; i < strs.size(); i++) {
writer.print(i);
writer.println(strs.get(i));
}
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

题目有些细节,没有说明白,我就只写一点点,有细节需要去完善

public class FatherClass {

private String name;
private int age;

public FatherClass(){
//无参数构造方法
System.out.println("无参数构造方法");
}

public FatherClass(String name,int age){
System.out.println("有参数构造方法"+name+" "+age+"体现重载");
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

public void printf(){
System.out.println("我是父类的打印方法");
}

}



public class ChildClass extends FatherClass{

@Override
public void printf() {
// TODO Auto-generated method stub

System.out.println("我自己打印语句,重写父类方法");
}




}



public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FatherClass class1 = new FatherClass();
FatherClass class2 = new FatherClass("dog",123);
class1.printf();
class2.printf();
ChildClass class3 = new ChildClass();
class3.printf();

}

}

import java.util.Random;
import java.util.Scanner;

public class T {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int difficulty;//难度
int mode;//运算类型
int answer;//答案
int amount;//挑战题目数量
int score = 0;//得分
System.out.println("请输入难度(1:一位数、2:两位数、3:三位数):");
difficulty = in.nextInt();
System.out.println("请输入运算类型(1:加、2:减、3:乘、4:除):");
mode = in.nextInt();
System.out.println("请输入想要挑战的题目数量:");
amount = in.nextInt();

Random random = new Random();

for (int i = 0; i < amount; i++) {
if (difficulty == 1) {
if (mode == 1) {
int x = random.nextInt(10);
int y = random.nextInt(10);
System.out.println("第" + i + "题:");
System.out.print(x + " + " + y + " = ");
answer = in.nextInt();
if (answer == (x + y)) {
System.out.println("答对了
");
score++;
} else {
System.out.println("答错了,答案是:" + (x + y) + "
");
}
} else if (mode == 2) {
int x = random.nextInt(10);
int y = random.nextInt(10);
System.out.println("第" + i + "题:");
System.out.print(x + " - " + y + " = ");
answer = in.nextInt();
if (answer == (x - y)) {
System.out.println("答对了
");
score++;
} else {
System.out.println("答错了,答案是:" + (x - y) + "
");
}
} else if (mode == 3) {//乘法

} else if (mode == 4) {//除法 考虑小数的问题

} else {
throw new Exception("运算类型输入值不合法");
}

} else if (difficulty == 2) {
if (mode == 1) {
int x = random.nextInt(100);
int y = random.nextInt(100);
System.out.println("第" + i + "题:");
System.out.print(x + " + " + y + " = ");
answer = in.nextInt();
if (answer == (x + y)) {
System.out.println("答对了
");
score++;
} else {
System.out.println("答错了,答案是:" + (x + y) + "
");
}
} else if (mode == 2) {

} else if (mode == 3) {//乘法

} else if (mode == 4) {//除法 考虑小数的问题

} else {
throw new Exception("运算类型输入值不合法");
}
} else if (difficulty == 3) {
if (mode == 1) {
int x = random.nextInt(1000);
int y = random.nextInt(1000);
System.out.println("第" + i + "题:");
System.out.print(x + " + " + y + " = ");
answer = in.nextInt();
if (answer == (x + y)) {
System.out.println("答对了
");
score++;
} else {
System.out.println("答错了,答案是:" + (x + y) + "
");
}
} else if (mode == 2) {

} else if (mode == 3) {//乘法

} else if (mode == 4) {//除法 考虑小数的问题

} else {
throw new Exception("运算类型输入值不合法");
}
} else {
throw new Exception("难度输入值不合法");
}
}

System.out.println("挑战结束,您的分数为:" + score);
}

}


我就只举了加法的例子,其他运算的写法都是类似的,你照葫芦画瓢即可

运行结果:



用java写一个程序?
答:JAVA程序计算素数 设计JAVA application程序,计算出20000000~300000000之间所有的素数,并将找到的素数写入primefile.dat文件,以下是一个使用Java语言编写的程序,可以计算出20000000~300000000之间所有的素数,并将找到的素数写入primefile.dat文件:javaCopy code import java.io.FileOutputStream; import java.io...

编写一个JAVA程序,在一个4x4的矩阵中随机填入0和1,打印该矩阵,找到第...
答:} System.out.println(); } int maxR = 0;//保存行出现1的次数的最大值, int maxC = 0;//保存列出现1的次数的最大值, int row = 0;//行 int col = 0;//列 for (int i = 0; i < ary.length; i++) { int numR = 0;//每次循环一行的1的次数统计 ...

用JAVA编写一个程序,计算从1加到50求和,输出结果
答:Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 [1] 。Java具有简单性、面向对象、...

用JAVA语言编写一个程序,要求如下:
答:import java.util.Scanner;public class T {public static void main(String[] args) throws Exception {Scanner in = new Scanner(System.in);int difficulty;//难度int mode;//运算类型int answer;//答案int amount;//挑战题目数量int score = 0;//得分System.out.println("请输入难度(1:一...

JAVA编写程序?
答:System.out.println("Hello world");} };} }class Inner { public static class InnerDemo { public static void main(String[] args) { Outer.method().show();} } } 这个程序中定义了一个接口 Inter 和一个外部类 Outer。Outer 类中有一个静态方法 method,该方法返回了一个实现了 ...

java试编写一程序,可由键盘输入一个整数,然后判断该数值是正数还是负数...
答:import java.util.Scanner; public class TestJT { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入整数"); int input= sc.nextInt(); if(input>=0){ System.out.println("你输入的是正数"); }else{ ...

编写一个JAVA计算器程序
答:编写一个模拟计算器的JavaApplet或JavaApplication程序,使用面板和网格布局,添加3个文本框,其中两个作为操作数使用,另一个作为显示使用,4个“加减乘除”运算符按钮,一个“等号”... 编写一个模拟计算器的Java Applet或Java Application程序,使用面板和网格布局,添加3个文本框,其中两个作为操作数使用,另一个作为显示...

java编程:编写一个文件信息存储程序,用户通过键盘输入学生的姓名,性 ...
答:if(str.equals("y"))break; //如果输入的是y则退出程序 i++;} //关闭流 bw.close();fw.close();}catch(IOException ex1){ System.out.println ("输入输出异常");} System.out.println ("程序结束");} } 本人刚入手java 可能写得不是很好.. 希望能给你带来帮助..不足之处,敬请...

编写一个Java程序片断定义一个表示学生的类student,包括域“学号...
答:} public void setName(String name) { this.name = name;} public String getSex() { return sex;} public void setSex(String sex) { this.sex = sex;} public int getAge() { return age;} public void setAge(int age) { this.age = age;} }这问题很基础的,多看一下吧 ...

java编写一个“猜数”程序:该程序随机在1到1000的范围中选择一个供...
答:Java源程序附后。本程序的特点是:(1) 文本框只能输入纯数字;(2) 界面较美观;(3) 代码可读性较好,有适当的注释;(4) 窗体一出现就在桌面居中。import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;public class GuessNumber { private static final long ...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网