java程序怎麼寫
正好今天不忙,就當回憶回憶歷史吧,呵呵。
public class Animal {
private String name;
private int legs;
public Animal(){
this("AAA",4);
}
public Animal(String name, int legs){
this.name = name;
this.legs = legs;
}
public String getName() {
return name;
}
public int getLegs() {
return legs;
}
public void move(){
System.out.println(this.name+" Moving!!");
}
public void move(int n){
if(n<0)
return;
for (int i = 0; i < n; i++) {
System.out.println(this.name+" Moving!!");
}
}
}
public class Fish extends Animal {
public Fish(String name){
super(name,0);
}
public void move() {
System.out.println(getName()+" Swimming!!");
}
}
public class Bird extends Animal {
public Bird(String name){
super(name,2);
}
public void move() {
System.out.println(getName()+" Flying!!");
}
}
public class Zoo {
/**
* @param args
*/
public static void main(String[] args) {
Animal animal = new Animal();
Fish fish = new Fish("shayu");
Bird bird = new Bird("dayan");
}
}
2. Java 編寫程序package java06_12;import java.util.Scanner;public class PrintTriangle { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("請輸入一個奇數.."); while (true) { Scanner in = new Scanner(System.in); try { int num = in.nextInt();// 獲得輸入的數字 if(num > 0 && (num % 2) == 1) {//如果輸入的數字大32313133353236313431303231363533e59b9ee7ad9431333262363034於0且是奇數 for(int i = 1; i <= num; i += 2) { printNum(i, num);//按1,3,5。
的順序打印數據 } break;//打印完退出 } else { System.out.println("請輸入一個奇數,謝謝!"); continue;//如果不是大於0的奇數,重新輸入 } } catch (Exception e) { System.out.println("請輸入一個奇數,謝謝!"); continue;// 如果不是數字,重新輸入 } } } public static void printNum(int num, int max) { String str = ""; for(int j = 1; j <= (max - num) / 2; j++) { str += " ";//在數字前面加空格 } for(int i = 1; i <= num; i++) { str += num;//數字 } for(int j = 1; j <= (max - num) / 2; j++) { str += " ";//數字後面的空格 } System.out.println(str); }}寫的只要是奇數都行..如果要1-9的加個判斷就行了哈..。
3. JAVA程序怎麼寫正好今天不忙,就當回憶回憶歷史吧,呵呵。
public class Animal { private String name; private int legs; public Animal(){ this("AAA",4); } public Animal(String name, int legs){ this.name = name; this.legs = legs; } public String getName() { return name; } public int getLegs() { return legs; } public void move(){ System.out.println(this.name+" Moving!!"); } public void move(int n){ if(n<0) return; for (int i = 0; i < n; i++) { System.out.println(this.name+" Moving!!"); } }}public class Fish extends Animal { public Fish(String name){ super(name,0); }public void move() { System.out.println(getName()+" Swimming!!"); }}public class Bird extends Animal { public Bird(String name){ super(name,2); } public void move() { System.out.println(getName()+" Flying!!"); }}public class Zoo { /** * @param args */ public static void main(String[] args) { Animal animal = new Animal(); Fish fish = new Fish("shayu"); Bird bird = new Bird("dayan"); }}。
4. 這個java程序怎麼寫public class Book {
private String name;//名稱屬性
private Integer page; //頁數屬性
public Book(String name,Integer page){//帶參數的構造方法
this.name = name;
this.page = page;
}
//屬性的get,set方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getpage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
//get,set方法結束
/**
* @param args
*/
public static void main(String[] args) {
Map map = new HashMap(); //定義MAP
for (int i = 0; i
5. java程序編寫public class Calculate{ public static void main(String[] args){ int x = Integer.parseInt(args[0]); if(x<0){System.out.println("y="+(2*x-1));} else if(x==0){System.out.println("y=-1");} else if(x>0){System.out.println("y="+(3*x-1));} }}。
6. 用java編寫程序/** * 學生類 * @author kingcs * */class Student{ // 成員變量學號(學號爲最終變量) public final String stuNo = "No10000001"; // 年齡 public int stuAge; // 姓名 public String stuName; // 班級 public String stuClass; // 學校 public School stuSchool; // 構造方法以完成對學生對象的初始化 public Student(){ this.stuAge = 22; this.stuName = "張三"; this.stuClass = "三(1)班"; School sch = new School(); sch.schName = "北京一中"; this.stuSchool = sch; } // 添加成員方法getInfo() public void getInfo(){ System.out.println("學生編號:" + this.stuNo + " 學生姓名:" + this.stuName + " 學生年齡:" + this.stuAge + " 所在班級:" + this.stuClass + " 所在學校:" + this.stuSchool.schName); }}/** * 學校類 * @author kingcs * */class School{ // 學校名稱 public String schName;}/** * 測試類 * @author kingcs * */public class Test_student_school { // main方法 public static void main(String[] args) { // 創建一個學生對象 Student stu = new Student(); // 並驗證學生類中所有方法 stu.getInfo(); }}// 結果學生編號:No10000001 學生姓名:張三 學生年齡:22 所在班級:三(1)班 所在學校:北京一中你要的可能是這樣的,希望能夠幫助你。
7. java 程序編寫 import java.util.Scanner;public class TestOut { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("請輸入一個單詞:"); String InputWord =input.next(); for(int i=0;i
-
魔獸爭霸真三黃忠出什麼裝備
魔獸爭霸真三黃忠的出裝如下:遊戲出門裝。二石環或者四樹枝,可加生命值、加物理抗性、加魔法抗性、加攻擊速度;遊戲前期出裝。出個護腕和飛鞋,黃忠中期較依賴移動速度;遊戲後期出裝。在護腕的基礎上出銀劍或血斧,若發育較好可以出個玄武甲。...
-
2023年男方首付婚前購買的房子離婚怎麼分
法律分析:婚前男方首付,若僅登記男方個人名字的,對於首付款部分屬於男方的個人財產,女方無權分割;對於婚後共同還貸部分和房產增值部分屬於夫妻共同財產,夫妻雙方可以均等分割。若房產登記在雙方名下,屬於夫妻共同財產,夫妻雙方可以均等分割。法律依據:《中華人民共和國...
-
房地產開發企業土地使用稅的納稅起止期限的確定
1、根據《城鎮土地使用稅暫行條例》第八條規定:土地使用稅按年計算、分期繳納,繳納期限由省、自治區、直轄市人民政府確定。《江蘇省地方稅務局關於明確地方稅務部門部分稅種納稅期限和納稅限額的通知》(蘇地稅函[2006]47號)規定,城鎮土地使用稅的納稅期限爲:企業按季...
-
關於讀書朱熹的名言有哪些
1、讀書之法,在循序而漸進,熟讀而精。2、讀書有三到,謂心到,眼到,口到。3、立身以立學爲先,立學以讀書爲本。4、爲學之道,莫先於窮理;窮理之要,必先於讀書。5、讀書無疑者,須教有疑,有疑者,卻要無疑,到這裏方是長進。6、讀書譬如飲食,從容咀嚼,其味必長;大嚼大咀,終不知味也。...