控制臺小游戲 class YZDEL
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供公主嶺網(wǎng)站建設(shè)、公主嶺做網(wǎng)站、公主嶺網(wǎng)站設(shè)計、公主嶺網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、公主嶺企業(yè)網(wǎng)站模板建站服務(wù),十載公主嶺做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
{
public static void main(String[] args)
{
java.util.Random Shiji = new java.util.Random();
java.util.Scanner Shuru = new java.util.Scanner(System.in);
java.util.Scanner Nandu = new java.util.Scanner(System.in);
int YingxHP = 20;
int YingxMP = 0;
int MogHP = 20;
int MogMP = 0;
int MogDo = 0;
int fangyu = 0;
System.out.println("┏━━━━╮┏━━┣┣┓ ╮ ┓┏━┳━┳┓┓━┓ ");
System.out.println("┏┣━━━┓┏━━┣┣┓ ┃┏ ┃ ┃┓┃ ╯ ");
System.out.println("┣┣━━━┫╭━━┻╯╮ ┃╰┓┃ ┃╯┏━┣━━┓");
System.out.println("┣┣━━━┫┏━━━━┓╭━━┣━┛┗━┻━┻┛┃┃");
System.out.println("┏┣━━━┓┣━━━━┫ ┃┃┃┗╮╮┃┃┣━╯");
System.out.println(" ┛┗╯┗━━━━╯┗╯╰╰━━┛┛┗━╯╰━┛");
System.out.println();
System.out.println(" 作者:天狐空幻");
System.out.println();
System.out.println("說明:勇者的操作方式為以下所示:");
System.out.println(" 使用攻擊需消耗1MP 傷害1HP");
System.out.println(" 使用蓄力可增加1MP 傷害0HP");
System.out.println(" 使用躲閃需消耗0MP 傷害0HP 躲避攻擊");
System.out.println(" 使用重?fù)粜柘?MP 傷害2HP 防御無效");
System.out.println(" 惡龍攻擊力高, 注意防御是取勝的關(guān)鍵");
System.out.println(" 惡龍MP達(dá)到4時可能會放出火焰無法躲避");
System.out.println(" 準(zhǔn)備說明完畢,那么讓我們來挑戰(zhàn)惡龍吧!");
System.out.println("==================================");
//難度選擇
System.out.println("請選擇難度");
System.out.println("1.娛樂 2.挑戰(zhàn) 3.噩夢");
int ND = Nandu.nextInt();
System.out.println("==================================");
while(true)
{
//HP,MP的顯示
System.out.print("勇者: ");
System.out.print(" HP ");
for(int x=YingxHP;x0;x--) System.out.print("*");
System.out.print(" "+YingxHP);
System.out.println();
System.out.print(" ");
System.out.print(" MP ");
for(int x=YingxMP;x0;x--) System.out.print("*");
System.out.print(" "+YingxMP);
System.out.println();
System.out.print("惡龍: ");
System.out.print(" HP ");
for(int y=MogHP;y0;y--) System.out.print("*");
System.out.print(" "+MogHP);
System.out.println();
System.out.print(" ");
System.out.print(" MP ");
for(int y=MogMP;y0;y--) System.out.print("*");
System.out.print(" "+MogMP);
System.out.println();
System.out.println("==================================");
//勝利判定
if(YingxHP1) {System.out.println();System.out.println("勇者HP為0! 不..不可能..我怎么會..勇者倒下了。再接再厲吧!~");System.out.println();break;}
if(MogHP1) {System.out.println();System.out.println("惡龍HP為0! 惡龍絕望的哀鳴中倒了下去。勇者勝利了。恭喜你挑戰(zhàn)成功!!");System.out.println();break;}
//角色輸入判定
System.out.println("你要做什么:");
System.out.println("1.攻擊 2.蓄力");
System.out.println("3.躲閃 4.重?fù)?);
System.out.println("____________________");
int Do = Shuru.nextInt();
//敵人輸入判定
//娛樂難度
if(ND==1){
for(int i=1;i3;i++) MogDo = Shiji.nextInt(4);}
//挑戰(zhàn)難度
if(ND==2){
if(YingxMP==0MogMP==0) {MogDo = 0;}
else if(MogMP==0){for(int i=1;i3;i++) MogDo = Shiji.nextInt(2);}
else if(YingxMP2MogMP2) MogDo = 2;
else if(MogMP4) {for(int i=1;i4;i++) MogDo = Shiji.nextInt(3);}
else MogDo = 3;}
//噩夢難度
if(ND==3){
if(Do==1) MogDo=1;
if(Do==2MogMP0) MogDo=2;
if(Do==2MogMP==0) MogDo=0;
if(Do==3MogMP4) MogDo=0;
if(Do==3MogMP=4) MogDo=3;}//變態(tài)判定。。
//戰(zhàn)斗分析
//防御
if(Do==3) {fangyu=1;System.out.println("你靈巧的躲避攻擊!");}
if(MogDo==1) {fangyu=1;System.out.println("惡龍進(jìn)行防御!");}
//角色判定
if(Do==1YingxMP==0) {System.out.println("MP不足!");}
if(Do==1YingxMP0) {
if(fangyu==0) {MogHP=MogHP-1;YingxMP=YingxMP-1;System.out.println("你發(fā)動攻擊!");}
if(fangyu==1) {YingxMP=YingxMP-1;System.out.println("你的攻擊被格擋!");}}
if(Do==2) {YingxMP=YingxMP+1;System.out.println("你進(jìn)行蓄力!");}
if(Do==4YingxMP3) {System.out.println("MP不足!");}
if(Do==4YingxMP2) {MogHP=MogHP-2;YingxMP=YingxMP-3;System.out.println("你發(fā)動重?fù)簦?);}
if(Do 4) System.out.println("你不知所措...");
//敵人判定
if(MogDo==2MogMP==0) {System.out.println("惡龍在發(fā)呆!");}
if(MogDo==2MogMP0) {
if(fangyu==0) {YingxHP=YingxHP-2;MogMP=MogMP-1;System.out.println("惡龍發(fā)動攻擊!");}
if(fangyu==1) {MogMP=MogMP-1;System.out.println("惡龍的攻擊被躲開了!");}}
if(MogDo==0) {MogMP=MogMP+1;System.out.println("惡龍進(jìn)行蓄力!");}
if(MogDo==3MogMP4) {System.out.println("惡龍在發(fā)呆!");}
if(MogDo==3MogMP3) {YingxHP=YingxHP-4;MogMP=MogMP-4;System.out.println("惡龍發(fā)動火焰吐吸!躲避不能!");}
//結(jié)束
fangyu = 0;
MogDo = 0;
System.out.println("____________________");
System.out.println();
System.out.println("=================================="); }
}
}
最簡單的java代碼肯定就是這個了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是應(yīng)該是所有學(xué)java的新手看的第一個代碼了。如果是零基礎(chǔ)的新手朋友們可以來我們的java實驗班試聽,有免費的試聽課程幫助學(xué)習(xí)java必備基礎(chǔ)知識,有助教老師為零基礎(chǔ)的人提供個人學(xué)習(xí)方案,學(xué)習(xí)完成后有考評團(tuán)進(jìn)行專業(yè)測試,幫助測評學(xué)員是否適合繼續(xù)學(xué)習(xí)java,15天內(nèi)免費幫助來報名體驗實驗班的新手快速入門java,更好的學(xué)習(xí)java!
//第一題:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
public class ManageName {
ListString namelist = new ArrayListString();
public void PrintMenu() {
System.out.println("\n\r1.Add new name " + "2.Display all name"
+ " 3.Quit"
+ "\nPlease select menu(1,2,3)");
}
public void displayname() {
for (int w = 0; w this.namelist.size(); w++) {
System.out.println("Name" + w+":" + this.namelist.get(w));
}
}
public List addName(String name) {
namelist.add(name);
return namelist;
}
public static void main(String[] args) throws IOException {
ManageName a = new ManageName();
a.addName("jing5083394");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while (true) {
a.PrintMenu();
String content = in.readLine();
if (content.equalsIgnoreCase("3")) {
break;
} else if (content.equalsIgnoreCase("1")) {
String name;
BufferedReader in2 = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("Please input the Name to add new user");
String content2 = in.readLine();
name = content2;
a.addName(name);
System.out.println("Add name successfully\r\n");
}
else if (content.equalsIgnoreCase("2")) {
a.displayname();
}
else {
System.out.println("Invalid selections!\n");
}
}
}
}
//第二題: 把文件放到namefile.txt
/*
* 從namefile.txt文件中讀入的字符串全部轉(zhuǎn)換成大寫字母,
* 再按原來的順序輸出到y(tǒng)oursData.txt文件中。
*/
import java.lang.Character;
import java.io.*;
//將一個文件復(fù)制到另一個文件中(覆蓋)
public class Filestream {
public static void main(String args[]) {
try {
File inFile = new File("c:\\namefile.txt");
File outFile = new File("c:\\yoursData.txt");
FileInputStream fis = new FileInputStream(inFile); // 讀輸入文件
FileOutputStream fos = new FileOutputStream(outFile);
int c;
while ((c = fis.read()) != -1) {
c = Character.toUpperCase(c);
fos.write(c);
}// 寫入文件中
System.out.println("Output file finish");
fis.close();
fos.close();
} catch (FileNotFoundException e) {
System.out.println("FileStreamsTest: " + e);
} catch (IOException e) {
System.err.println("FileStreamsTest: " + e);
}
}
}
package com.zpp;public class Charge {
public static void main(String [] args) {
if(args.length ==0) {
System.out.println("parameter error!");
System.out.println("java com.zpp.Charge [int]");
return;
}
int min = Integer.parseInt(args[0]);
double money = 0.0;
if (min = 0) {
money =0.0;
System.out.println("not money");
} else if (min = 60) {
money = 2.0;
} else {
money = 2.0 + (min - 60) * 0.01;
}
System.out.println("please pay: " + money);
}
} 編譯:javac -d . Charge.java運行:java com.zpp.Charge 111
可以使用數(shù)組,來存儲輸入的3個數(shù)字,然后排序,得到最大值
也可以直接一邊輸出一邊判斷,參考代碼如下
import?java.util.Scanner;
public?class?Exam?{
public?static?void?main(String[]?args)?{
int?len?=3;
System.out.println("請輸入"+len+"個數(shù)字");
Scanner?sc?=?new?Scanner(System.in);
int?max?=?sc.nextInt();//假設(shè)第一次輸入的數(shù)字是最大,存在這里
for?(int?i?=?0;?i?len-1;?i++)?{
int?x?=?sc.nextInt();
if(xmax){//如果比max還要大.那么就替換掉max的值
max?=?x;
}
}
System.out.println("最大的數(shù)字是"+max);
}
}
測試
請輸入3個數(shù)字
2
1
6
最大的數(shù)字是6