帮忙用java基础语言编写一个程序 要求如下 请用java语言设计一个程序完成如下要求

\u7528Java\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u8981\u6c42\u5982\u4e0b

\u4f60\u8fd9\u4e2a\u9898\u76ee\u51fa\u5f97\u4e0d\u5927\u5408\u7406\u554a
\u8f93\u51fa\u4e2a\u4eba\u4fe1\u606f\u4e0d\u9700\u8981\u8fd4\u56de\u503c\u548c\u5faa\u73af\u8bed\u53e5

import java.util.ArrayList;import java.util.List;public class SubNumber { public static void print(List list){ for(int i = 0;i array, int size) { if (array.size() == (size - 1)) { array.add(sum); // \u60f3\u8981\u7684\u6570\u7ec4 print(array); count++; } else { for (int i = 0; i subarray = new ArrayList(); subarray.addAll(array); subarray.add(i); int subsum=sum-i; subNaturalNumber(subsum, subarray, size); } } } public static void main(String[] args) { ArrayList list = new ArrayList(); subNaturalNumber(16, list, 14);//\u8ba1\u7b97\u51fd\u6570\uff0c16\u5206\u89e3\u621014\u4e2a\u6570\u5b57\uff0c\u5176\u4ed6\u8bf7\u81ea\u884c\u4fee\u6539\u53c2\u6570 System.out.println(count);//\u7edf\u8ba1\u591a\u5c11\u79cd\u7ed3\u679c }}
//\u7531\u4e8e\u8fd0\u884c\u65f6\u95f4\u8f83\u957f\uff0c\u7ed3\u679c\u53ea\u622a\u90e8\u5206\u3002\u6700\u540e16\u768414\u9879\u5206\u89e3\u517167863915\u79cd\uff0c15\u768414\u9879\u5206\u89e3\u517137442160\u79cd\u3002

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<String> strs = new LinkedList<String>();

// 读取文件中的内容到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();
}
}
}

不要急,帮你写,周一给你,你不留个邮箱?

//主要功能做出来
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;

public class JieXi {

private LinkedList list = new LinkedList();
private String sourcePath;
private String targetPath;

public void setSourcePath(String sourcePath) {
this.sourcePath = sourcePath;
}

public void setTargetPath(String targetPath) {
this.targetPath = targetPath;
}

public void setList() {
FileReader fr;
try {
File file = new File(sourcePath);
Runtime.getRuntime().exec("notepad " + sourcePath);
fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
while (true) {
String linestr = br.readLine();
if (linestr != null) {
list.add(linestr);
} else
break;
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public void intoTxtFile() {
try {
ToFile tf = new ToFile(targetPath);
tf.newFile();
setList();
for (int i = list.size(); i > 0; i--) {
tf.toTxtFile("[" + i + "]" + (String) list.get(i - 1) + "\r\n");
}
tf.close();
Runtime.getRuntime().exec("notepad " + targetPath);
} catch (IOException e) {
e.printStackTrace();
}
}

public static void main(String[] args) throws FileNotFoundException {
JieXi jx = new JieXi();
jx.setSourcePath("D:\\4.txt");
jx.setTargetPath("D:\\2.txt");
jx.intoTxtFile();
}
}

/**
* 写入TXT文件类
*/
class ToFile {
private String filename = "D:\\default.txt";
private File file;
private PrintWriter pw;

public ToFile() throws FileNotFoundException {
newFile();
pw = new PrintWriter(file);
}

public ToFile(String filename) throws FileNotFoundException {
this.filename = filename;
newFile();
pw = new PrintWriter(file);
}

public void newFile() {
file = new File(filename);
if (!file.exists())
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}

public void toTxtFile(String str) {
pw.write(str);
}

public void close() {
pw.flush();
pw.close();
}
}

  • 濡備綍鐢╦ava璇█缂栧啓涓涓绋嬪簭?
    绛旓細鏍规嵁鐩殑鍒ゆ柇锛岄渶瑕佽皟鍙栧埌鐨勫嚱鏁版湁randi銆乵od銆乵ean銆乫ind锛屽垎鍒敤浜庝骇鐢熼殢鏈烘暣鏁般佸垽鏂槸鍚︿负鍋舵暟銆佽绠楀钩鍧囨暟銆佸鎵炬弧瓒虫潯浠跺厓绱犵殑涓嬫爣銆備唬鐮佸涓嬶細clc;clear;n=randi([10,99],[1,20])%浜х敓闅忔満鏁帮紝鍦10鍒99涔嬮棿鐨勫潎鍖闅忔満鏁 a=mean(n)%璁$畻骞冲潎鏁 n(find(n...
  • 濡備綍鐢╦ava璇█缂栧啓涓涓璁$畻鍦嗙殑闈㈢Н鐨勭▼寮?
    绛旓細鐢↗AVA鍐欎竴涓姹傚渾鐨勯潰绉殑绋嬪紡銆傝皝甯甯繖 private static final double e = 3.1415926; public static void main(String[] args){ System.out.println("璇疯緭鍏ュ渾鐨勫崐寰:"); Scanner scan = new Scanner(System.in); double r = scan.nextDouble(); getCircleArea(r); } /** ...
  • 鐢↗AVA缂栧啓涓涓绋嬪簭,瑕佹眰濡備笅:
    绛旓細import java.util.Scanner;public class StudentTest {public static void main(String[] args) {Student student = new Student();Scanner sc = new Scanner(System.in);System.out.println("璇疯緭鍏ュ鍚嶏細");student.setName(sc.next());System.out.println("璇疯緭鍏ユу埆锛");student.setSex(sc....
  • 浣跨敤Java璇█缂栧啓涓娈电▼搴,瀹炵幇浠庢帶鍒跺彴杈撳叆骞惰緭鍑涓涓3琛3鍒楃殑鏁扮粍...
    绛旓細import java.util.Scanner;public class P { public static void main(String[] args){ int[][] a=new int[3][3];Scanner sc = new Scanner(System.in);System.out.println("璇疯緭鍏9涓暣鏁帮細");for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ a[i][j]=sc.nextInt();} ...
  • 鐢╦ava璇█缂栧啓
    绛旓細student.isPass();}}2銆佸鐢熺被public class Student {/** * 鐢╦ava璇█缂栧啓缂栧啓涓涓绫籗tudent锛屾弿杩板鐢熺殑瀛﹀彿銆佸鍚嶅拰鎴愮哗銆傚鍙风敤long锛屾垚缁╃敤float锛屽鍚嶇敤String銆傚鐢熸嫢鏈夊垽鏂嚜宸辩殑鎴愮哗鏄惁鍙婃牸鐨勫姛鑳斤紙鏂规硶鍚嶏細isPass()锛夈傚苟鑳藉鎵撳嵃杈撳嚭鑷繁鐨勫鍚嶅強鏄惁鍙婃牸淇℃伅锛堟柟娉曞悕锛歱rintInfo()锛夈傞拡瀵筍t...
  • 鐢╦ava璇█鎬庝箞鍘诲仛涓涓椤甸潰?
    绛旓細鐢╦ava鏉缂栧啓缃戦〉,鐩墠姣旇緝娴佽鐨勬槸SSH锛坰truts2+spring+hibernate锛夋鏋躲傚叾瀹炲彧瑕佹湁servlet鍜孞SP鍩虹灏卞彲浠ュ疄鐜帮紝妗嗘灦鍙槸楂樻晥鐨勫紑鍙戝拰绠$悊銆傛帹鑽愪娇鐢⊿SH妗嗘灦杩涜寮鍙戙備娇鐢╯truts2鏉ュ疄鐜伴〉闈㈣烦杞紝浠栫殑鏍囩涔熷彲浠ュ啓JSP鐣岄潰銆備娇鐢╤ibernate鏉ヨ繘琛屾暟鎹簱鎿嶄綔鐨勫皝瑁咃紝杩涜鑷姩绠$悊銆備娇鐢╯pring鍙互鏁村悎浠ヤ笂涓や釜锛屼娇...
  • 甯繖鐢╦ava鍩虹璇█缂栧啓涓涓绋嬪簭 瑕佹眰濡備笅
    绛旓細import java.util.LinkedList;import java.util.List;public class QuestionOne { / 鎵撳紑涓涓鏂囨湰鏂囦欢锛屾瘡娆¤鍙栦竴琛屽唴瀹广傚皢姣忚浣滀负涓涓猄tring璇诲叆锛屽苟灏嗛偅涓猄tring瀵硅薄缃叆涓涓狶inkedlist涓傛寜鐩稿弽鐨勯『搴忔墦鍗板嚭Linkedlist涓墍鏈夌殑琛屻傚悓鏍蜂篃鎵撳紑涓涓枃鏈枃浠讹紝浠ヤ究灏嗘枃鏈啓鍏ュ叾涓傚皢Linkedlist涓殑鍚勮闅忓悓...
  • 鐢↗AVA璇█缂栧啓涓涓绋嬪簭,瑕佹眰濡備笅:
    绛旓細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璇█缂栧啓涓涓璁$畻鍣,璇ヨ绠楀櫒鑳藉姝f暟銆佽礋鏁(杩欓噷鐨勬鏁般佽礋鏁...
    绛旓細tf1.setText(""); addmyMenu(); } public void addmyMenu() { mb1 = new MenuBar(); //鐢熸垚涓涓鑿滃崟鏍 f.setMenuBar(mb1); //妗嗘灦f涓婃坊鍔犺彍鍗曟爮 mf1 = new Menu("缂栬緫(E)"); //鐢熸垚涓涓彍鍗 me1 = new Menu("鏌ョ湅(V)"); mh1 = new Menu("甯姪(H)"); mb1.add(mf1); //鑿滃崟...
  • 鐢╦ava缂栧啓涓涓绋嬪簭?
    绛旓細Java鏄竴闂ㄨ绠楁満缂栫▼璇█锛岄潰鍚戝璞$殑缂栫▼璇█銆侸ava鍙互寮鍙戝悗绔紝鏈塻pring锛宻pringmvc锛宻pringboot锛宻pringcould绛夌瓑閮芥槸浣跨敤Java寮鍙戙侸ava涔熸湁鍓嶇妗嗘灦锛屾湁Jquery锛孞avaScript锛孞SP锛孲ervlet锛岀粺绉癑avaWEB寮鍙戙浣跨敤Java缂栧啓涓涓绋嬪簭寰堢畝鍗曪紝鎸夌収鐩稿叧鐨勬ā鏉匡紝鍔犱笂涓氬姟浠g爜灏卞彲浠ュ疄鐜颁竴濂楃郴缁熴
  • 扩展阅读:java.52emu.cn ... java语言基础知识 ... java编程零基础入门 ... java基础知识大全 ... 零基础java自学教程 ... java自学免费教程网站 ... javascript免费网站 ... java基础入门电子版 ... 黑马java视频 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网