编写java程序

java\u5c0f\u7a0b\u5e8f\u7f16\u5199

\u697c\u4e3b\uff0c\u4ee5\u4e0b\u662f\u6211\u7684\u5b9e\u73b0\u65b9\u5f0f\uff0c\u770b\u770b\u662f\u4e0d\u662f\u4f60\u60f3\u8981\u7684\uff0c\u54ea\u91cc\u4e0d\u6e05\u695a\u7684\u53ef\u4ee5\u5355\u72ecM\u6211\u3002
import java.util.Arrays;
import java.util.Comparator;

public class Student {

private int id;

private String name;

private String birthday;

public Student(int id, String name, String birthday) {

this.id = id;
this.name = name;
this.birthday = birthday;
}

public static void main(String[] args) {

Student s1 = new Student(1, "\u5f20\u4e09", "1983-01-22");
Student s2 = new Student(2, "\u5f20\u4e00", "1983-01-21");
Student s3 = new Student(3, "\u5f20\u7b11\u4e00", "1983-01-27");
Student s4 = new Student(4, "\u5f20\u542b\u4e00", "1983-01-01");

Student[] students = { s1, s2, s3, s4 }; //\u5c064\u4e2a\u5b66\u751f\u5bf9\u8c61\u88c5\u5165\u6570\u7ec4\u4e2d

//\u73b0\u6839\u636e\u51fa\u751f\u65e5\u671f\u5bf9\u6570\u7ec4\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff0c\u7531\u4e8eString\u5df2\u7ecf\u5b9e\u73b0\u4e86Comparable\u63a5\u53e3\uff0c\u53ef\u4ee5\u76f4\u63a5\u5229\u7528compareTo\u65b9\u6cd5\u8fdb\u884c\u6bd4\u8f83
Arrays.sort(students, new Comparator() {

public int compare(Student o1, Student o2) {
return o1.getBirthday().compareTo(o2.getBirthday());
}

});
//\u6253\u5370\u6392\u5e8f\u540e\u7684\u7ed3\u6784
System.out.println(Arrays.toString(students));

Student[] newStudents = new Student[students.length];
int i = 0;
for (Student s : students) {
if (s.getName().indexOf("\u4e00") != -1) {
newStudents[i] = s;
i++;
}

}

//\u6253\u5370\u641c\u7d22\u51fa\u7684\u59d3\u540d\u542b\u201c\u4e00\u201d\u7684\u5b66\u751f
System.out.println(Arrays.toString(newStudents));

}

@Override
public String toString() {
// TODO \u81ea\u52a8\u751f\u6210\u65b9\u6cd5\u5b58\u6839
return "Student\u59d3\u540d:" + this.name + ",\u51fa\u751f\u65e5\u671f\uff1a" + this.birthday;
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public void setId(int id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}

public String getBirthday() {
return birthday;
}

public void setBirthday(String birthday) {
this.birthday = birthday;
}
}

import java.util.Scanner;


public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("\u8f93\u5165\u4e24\u4e2a\u6570\u5b57\u5e76\u8ba1\u7b97\u548c");
System.out.println("\u7b2c1\u4e2a\u6570\u5b57\uff1a");
String no1 = scanner.next();
System.out.println("\u7b2c2\u4e2a\u6570\u5b57\uff1a");
String no2 = scanner.next();
try{
int int1 = Integer.valueOf(no1);
int int2 = Integer.valueOf(no2);
System.out.println("\u7ed3\u679c\uff1a"+no1+"+"+no2+"="+(int1+int2));
}catch (NumberFormatException e) {
System.out.println("\u8f93\u5165\u7684\u4e0d\u662f\u4e00\u4e2a\u6570\u5b57");
}
}
}

package count_source;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
    public static void main(String[] args) throws IOException {
        test(new File("C:\\Windows"));
    }
    
    public static void test(File  all) throws IOException {
        File[] ps = all.listFiles();
        
        for (int i = 0; i < ps.length; i++) {
            String pathString = ps[i].getPath();
            if(pathString.endsWith(".win")){
                System.out.print(pathString+" : ");
                System.out.println(readFile(pathString));
            }else if(ps[i].isDirectory()){
                //System.out.println(pathString);
                test(ps[i]);
            }
        }
    }
    
    public static String readFile(String path) throws IOException {
        BufferedReader br =new BufferedReader(new InputStreamReader(
                new FileInputStream(new File(path)),"UTF-8"));
        StringBuilder sb = new StringBuilder();
        String len;
        while ((len = br.readLine()) !=null) {
            sb.append(len);
        }
        br.close();
        return  sb.toString();
    }
}


File file = new File("D:\est.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(
new BufferedInputStream(new FileInputStream(file)), "UTF-8"));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();

百度一大堆啊。随便怎么写都行



  • 鐢java鍐涓涓绋嬪簭?
    绛旓細JAVA绋嬪簭璁$畻绱犳暟 璁捐JAVA application绋嬪簭,璁$畻鍑20000000~300000000涔嬮棿鎵鏈夌殑绱犳暟,骞跺皢鎵惧埌鐨勭礌鏁板啓鍏rimefile.dat鏂囦欢,浠ヤ笅鏄竴涓娇鐢↗ava璇█缂栧啓鐨勭▼搴忥紝鍙互璁$畻鍑20000000~300000000涔嬮棿鎵鏈夌殑绱犳暟锛屽苟灏嗘壘鍒扮殑绱犳暟鍐欏叆primefile.dat鏂囦欢锛歫avaCopy code import java.io.FileOutputStream; import java.io...
  • 鐢╡cilpse寮鍙戜竴涓java绋嬪簭
    绛旓細3銆佸垱寤Java绫伙細榧犳爣鍙抽敭鍗曞嚮鍖呭悕锛岄夋嫨銆怤ew銆戔啋銆怌lass銆戜細鍑虹幇涓涓怤ewJava Class銆戝璇濇锛屽湪瀵硅瘽妗嗕腑銆怤ame銆戞枃鏈琛ㄧず绫诲悕锛岃繖閲屽垱寤轰竴涓狧elloWorld绫伙紝鍗曞嚮銆怓inish銆戞寜閽紝灏卞畬鎴愪簡HelloWorld绫荤殑鍒涘缓銆傝繖鏃讹紝鍦ㄢ渃n.itcast.chapter01鈥濆寘涓嬪氨鍑虹幇浜嗕竴涓狧elloWorld.java鏂囦欢銆4銆缂栧啓绋嬪簭浠g爜锛氬垱...
  • 濡備綍缂栧啓鈥Java绋嬪簭鈥?
    绛旓細("\t\t\t\t\t***8:缁撴潫绋嬪簭 ***\t\t\t\t\t");\x0d\x0a try{\x0d\x0a byte b=sc.nextByte();\x0d\x0a switch(b){\x0d\x0a case 1:\x0d\x0a stu.inputInfo();break;\x0d\x0a case 3:\x0d\x0a stu.getSum();break;\x0d\x0a case 4:\x0d\x0a stu...
  • JAVA缂栧啓绋嬪簭?
    绛旓細System.out.println("Hello world");} };} }class Inner { public static class InnerDemo { public static void main(String[] args) { Outer.method().show();} } } 杩欎釜绋嬪簭涓畾涔変簡涓涓帴鍙 Inter 鍜屼竴涓閮ㄧ被 Outer銆侽uter 绫讳腑鏈変竴涓潤鎬佹柟娉 method锛岃鏂规硶杩斿洖浜嗕竴涓疄鐜颁簡 ...
  • 鐢java缂栧啓涓涓绋嬪簭?
    绛旓細Java鏄竴闂ㄨ绠楁満缂栫▼璇█锛岄潰鍚戝璞$殑缂栫▼璇█銆侸ava鍙互寮鍙戝悗绔紝鏈塻pring锛宻pringmvc锛宻pringboot锛宻pringcould绛夌瓑閮芥槸浣跨敤Java寮鍙戙侸ava涔熸湁鍓嶇妗嗘灦锛屾湁Jquery锛孞avaScript锛孞SP锛孲ervlet锛岀粺绉癑avaWEB寮鍙戙備娇鐢Java缂栧啓涓涓绋嬪簭寰堢畝鍗曪紝鎸夌収鐩稿叧鐨勬ā鏉匡紝鍔犱笂涓氬姟浠g爜灏卞彲浠ュ疄鐜颁竴濂楃郴缁熴
  • 鏍规嵁浠ヤ笅浠诲姟瑕佹眰,缂栧啓Java搴旂敤绋嬪簭?
    绛旓細鎸夌収棰樼洰瑕佹眰缂栧啓鐨Java绋嬪簭濡備笅 娉ㄦ剰 璇蜂娇鐢ㄤ綘鐨勭湡瀹炲鍚嶅拰鐝骇鏇挎崲Test绫讳腑 鍒涘缓Student瀵硅薄stu鏃剁敤鐨"寮犱笁"鍜"20璁$畻鏈哄簲鐢01鐝"import java.util.Scanner;class Student{ private String name,classname;private int starnum,scorenum;private int[] scores;public void setStarNum(int n){ this.star...
  • java璇█濡備綍缂栧啓绋嬪簭?
    绛旓細濡備笅锛(1) 涓涓Java璇█寮鍙戝伐鍏峰寘(Java Devekopment Kit)锛屽叾涓寘鎷琂ava 缂栬瘧鍣ㄥ拰Java杩愯鐜銆(2) 涓浠絁ava璇█API鏂囨。锛岀洰鍓嶇増鏈殑Java璇█API鏂囨。鍚屾牱鍙互鍏嶈垂銆(3) 涓涓狫ava璇█闆嗘垚寮鍙戠幆澧冿紝鑳藉鍦ㄥ叾涓紪杈慗ava浠g爜锛屽苟涓旇繘琛岀紪璇戜笌璋冭瘯銆傛帹鑽愪娇鐢ㄧ殑闆嗘垚寮鍙戠幆澧冩槸JCreator銆傚缓璁幓鎵捐佸笀璁╄佸笀 ...
  • 濡備綍瀛︿範缂栧啓java 搴旂敤绋嬪簭
    绛旓細鍒涘缓涓涓狧TML椤甸潰鏉ュ寘鍚皬绋嬪簭銆傚彟寮涓涓浜嬫湰绐楀彛銆傚綍鍏ヤ笅闈㈢殑鍐呭锛氬皢姝ゆ枃浠跺瓨浜庡悓涓鐩綍涓紝鏂囦欢鍚嶄负applet.htm銆Java绋嬪簭鎬庢牱缂栧啓 4 1.杩愯Java绋嬪簭 銆傚湪鎮ㄧ殑MS-DOS绐楀彛涓敭鍏ワ細appletviewer applet.htm 搴旇鍙互鐪嬭涓鏉′粠宸︿笂瑙掑埌鍙充笅瑙掔殑瀵硅绾匡細锛堝涓婂浘鎵绀猴級灏嗗皬绋嬪簭鏌ョ湅鍣ㄧ殑绐楀彛鎷夊ぇ涓浜...
  • 鍦java涓缂栧啓绋嬪簭,瀹氫箟涓涓鐢熺被
    绛旓細import java.util.ArrayList;import java.util.List;/ 缂栧啓涓涓Java搴旂敤绋嬪簭锛岃绋嬪簭鍖呮嫭3涓被锛氬畾涔変竴涓鐢熺被锛孲tudent鏈夊鍚嶏紝瀛﹀彿锛岄夊鐨勮绋嬪垪琛 瀹氫箟涓涓绋嬬被锛氳绋嬪悕绉帮紝璇剧▼鍒嗘暟 (1)鍒濆鍖栦竴涓鐢燂紝閫夋嫨浜嗕笁闂ㄨ绋嬶紝骞舵坊鍔犲埌瀛︾敓鐨勫睘鎬т腑 (2)瀹炵幇缁熻瀛︾敓鐨勬诲垎鍔熻兘 1.姝g‘缂栧啓2涓被锛5...
  • 鐢java缂栧啓涓涓绋嬪簭
    绛旓細浠g爜濡備笅锛歩mport java.util.Scanner;public class App {public static void main(String[] argv) {Scanner scanner = new Scanner(System.in);int num1 = scanner.nextInt();int num2 = scanner.nextInt();if (num1 > num2) {int temp = num1;num1 = num2;num2 = temp;}for (; ...
  • 扩展阅读:入门的java游戏小程序 ... java代码生成器 ... java编程入门 ... 一个最简单的java程序 ... 《java程序设计》 ... java程序步骤 ... 编写简单的java程序 ... hello world程序编写java ... java编程必背的100个程序 ...

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