一道Java编程题,拜托了 一道简单的java编程题,各位大神拜托了!
\u4e00\u9053Java\u7f16\u7a0b\u9898\uff0c\u62dc\u6258\u4e86\u5404\u4f4d\u5927\u795e1.\u5b9a\u4e49\u4e00\u4e2aStudent\u7c7b\uff0c\u5305\u62ec\u5b66\u53f7\uff0c\u59d3\u540d\uff0c\u6210\u7ee9\u4e09\u4e2a\u5b57\u6bb5\uff0c\u751f\u6210get,set\u548ctoString\u65b9\u6cd5,\u5b9e\u73b0Comparable\u63a5\u53e3\uff0c\u91cd\u5199toCompare\u65b9\u6cd5\uff0c\u65b9\u6cd5\u91cc\u5c31\u662f\u672c\u9898\u7684\u903b\u8f91\uff0c\u5148\u6309\u6210\u7ee9\u6bd4\u8f83\uff0c\u518d\u6309\u5b66\u597d\u6bd4\u8f83\uff0c\u4f7f\u7528TreeSet\u4e0d\u5b9e\u73b0\u8fd9\u4e2a\u63a5\u53e3\u4f1a\u62a5\u9519\u3002
package Collection;public class Student implements Comparable {private long sno;private String name;private int score;public long getSno() {return sno;}public void setSno(long sno) {this.sno = sno;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getScore() {return score;}public void setScore(int score) {this.score = score;}@Overridepublic int compareTo(Student o) {// TODO Auto-generated method stubif (this.score o.score) {return -1;} else {if(this.sno<o.sno) {return 1;}else {return -1;}}}@Overridepublic String toString() {return "Student [sno=" + sno + ", name=" + name + ", score=" + score + "]";}}2.\u7136\u540e\u5199\u6d4b\u8bd5\u7c7b\uff0c\u751f\u6210\u5341\u4e2a\u5b66\u751f\uff0c\u7136\u540e\u63d2\u5165treeset\uff0c\u76f4\u63a5\u904d\u5386\u8f93\u51fa\u5c31\u662f\u6392\u5e8f\u597d\u7684\u7ed3\u679c\u3002
package Collection;import java.util.Random;import java.util.TreeSet;public class TreeSetTest {public static void main(String[] args) {TreeSet ts=new TreeSet();for(int i=0;i<10;i++) {Student stu=new Student();stu.setName("student"+i);stu.setSno(170201+i);stu.setScore(90+new Random().nextInt(10));ts.add(stu);}for(Student stu:ts) {System.out.println(stu);}}}\u6700\u540e\u8d34\u4e00\u4e2a\u8fd0\u884c\u7ed3\u679c
\u7b49\u697c\u4e0b\u7684\u7ed9\u4f60\u89e3\u7b54\u5427
\u5c45\u7136\u6ca1\u4eba\u56de\u7b54\u4f60,\u770b\u4e0b\u9762
public class Rectangles{ private int width; // \u5bbd\u5ea6 private int height; // \u957f\u5ea6 public void setWidth(int width){ this.width = width; } public int getWidth(){ return width; } public void setHeight(int height){ this.height = height; } public int getHeight(){ return height; } public int getSquare(){ return width * height; }}
package exam;
public class Test1 {
public static void main(String[] args) {
String NAME = "西海龙王";
int lowage=1998;
int nowage=2016;
int age=Age(lowage,nowage);
System.out.println(NAME+lowage+"年出生,今年"+age+"岁");
}
private static int Age(int i, int j) {
return j-i;
}
}
package exam
import java.util.Scanner;
public class Test1{
public static void main(String[] args){
String NAME="例如你叫某某";
System.out.println("请输入你的出生年份");
Scanner sc=new Scanner(System.in);
int cyear=sc.nextInt();
System.out.println("请输入当前年份");
int dyear=sc.nextInt();
System.out.println(NAME+cyear+"出生,今年"+(dyear-cyear)+"岁");
}
}
//我直接手打的,有些符号可能中英文不一样,你自己注意改
package exam;
public class Test1
{
public static void main(String[] args) throws Exception
{
int byear,dyear;
byear=Integer.parseInt(args[0]);
dyear=Integer.parseInt(args[1]);
System.out.printf("%s%d年出生,今年%d岁。",Test1.NAME,byear,(dyear-byear));
}
//修改NAME的值为你的名字
static final String NAME="你的名字";
}
private static String name="张三";
public static void main(String[] args) {
System.out.println(name+args[0]+"出生,今年"+(Integer.valueOf(args[1])-Integer.valueOf(args[0]))+"岁。");
}
代码如下:
package exam;
import java.util.Scanner;
public class Test1{
public static void main(String[] args){
String name = "zhangsan";
System.out.println("请输入你的出生年份: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String year = br.readLine();
System.out.println("请输入当前年份:");
String cyear= br.readLine();
System.out.println(name + year +"年出生,今年" + (Integer.valueOf(cyear) - Integer.valueOf(year) + "岁"));
}
}
绛旓細搴旇鏄繖鏍风殑鍚э紝瓒佹湁鐐圭┖灏卞府浣犲啓浜 import java.io.BufferedReader; import java.io.InputStreamReader; public class Demo { public static void main(String[] args)throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) ; System.out.print("...
绛旓細public class Student { private String name;private int age;private char sex;private int source;public Student(String name, int age, char sex, int source) { this.name = name;this.age = age;this.sex = sex;this.source = source;} public int getAge() { return age;} public ...
绛旓細StringBuffer sb=new StringBuffer("1234567");int length=sb.length();sb.reverse();for(int i=1,j=0;i<=(length-1)/3;i++,j++)sb.insert(3*i+j, ",");sb.reverse();System.out.println(sb.toString());缁撴灉1,234,567 鏂规硶姣旇緝bt涓鐐癸紝涓嶇煡閬撴晥鐜囧浣曪紝浣嗘槸缁撴灉杈惧埌浜嗭紝鍛靛懙 ...
绛旓細import java.util.Scanner;public class Circle { private String color;private int radius;public Circle() { } // 鏄剧ず棰滆壊 public String showColor() { return color;} // 璁剧疆棰滆壊 public void setColor(String color) { this.color = color;} // 鏄剧ず鍗婂緞 public int showRadius() { ret...
绛旓細java.util.Scanner scan = new java.util.Scanner(System.in);System.out.println("杈撳叆涓や釜鏁:");int inputA = scan.nextInt();int inputB = scan.nextInt();System.out.println("涓ゆ暟鏈澶у叕绾︽暟锛" + resultA.greatestCommonDenominator(inputA, inputB));System.out.println("涓ゆ暟鏈灏忓叕...
绛旓細鐪嬩綘閭d箞璐瑰姴鐨勬妸棰樻暡涓婃潵鈥︹︽垜灏卞府甯綘濂戒簡鈥︹java鑷鐨勫搱锛1290767680锛屾湁闂鍙互闂垜 濡傛灉鎴戜細鐨勮偗瀹氬憡璇変綘 1.鍙傛暟鍊间笉鍚 鍙傛暟绫诲瀷涓嶅悓 2.true false 3.鍗 interface 4.static 5.super 6.double float 7.false 8.package import 9.Label ttxy=new Label("娓告垙涓庡姩婕闄");Button...
绛旓細浠g爜Test.java import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.util.Scanner;public class Test {public static String strInfo(){Scanner sc = new Scanner(System.in);String name, sex, bj, info;int age;System.out.print("杈撳叆濮撳悕: ");name = sc....
绛旓細绗竴棰:public class Calutor { /* 澹版槑涓涓潤鎬佹柟娉曠敤鏉ユ眰姣忎釜鏁扮殑闃朵箻:闈欐佹柟娉曞彲浠ョ洿鎺ョ敤绫诲悕鏉ヨ皟鐢 */ public static int f(int a) { int temp = 1;for (int i = 1; i <= a; i++) { temp = temp * i;} return temp;} public static void main(String[] args) { int ...
绛旓細/ //鍒涘缓鎶借薄鐨勯煶涔怚nstrument绫伙紝鍦ㄨ绫诲畾涔変簡涓涓猵lay()寮瑰鏂规硶锛屽苟鍒涘缓涓や釜瀛愮被锛//閽㈢惔鍜屽皬鎻愮惔銆傚湪InstrumentTest绫讳腑瀹氫箟testPlay锛堬級鐨勬紨濂忔柟娉曪紝//璇ユ柟娉曟帴鍙楅煶涔愮被鐨勫璞″仛鏂规硶鐨勫弬鏁帮紝骞惰皟鐢ㄥ弬鏁扮殑play()鏂规硶杩涜婕斿 //鍒涘缓涓涓被鍚嶄负InstrumentTest.java婧愭枃浠讹紝鍙湪涓涓枃浠跺唴锛屽唴瀹瑰涓...
绛旓細Rectangle绫荤殑婧愮爜濡備笅锛歱ublic class Rectangle { //锛1锛 int绫诲瀷鐨剋idth銆乭eight灞炴 private int width,height;//锛2锛 2涓瀯閫犳柟娉曪紝涓涓槸鏃犲弬鏋勯犳柟娉曪紝涓涓瀯閫犳柟娉曞甫2涓弬鏁帮紝鍒嗗埆鏄柊鐭╁舰瀵硅薄鐨勯暱銆佸 public Rectangle(){ this(0,0);} public Rectangle(int w,int h){ width = w;...