第一個:
十年的寧洱網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。成都全網(wǎng)營銷的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整寧洱建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“寧洱網(wǎng)站設(shè)計”,“寧洱網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
import?java.util.Scanner;
/**
*?Created?by?Chen?on?2015/11/11.
*/
public?class?T?{
public?static?void?main(String[]?args)?{
int?temp?=?0;
Scanner?s?=?new?Scanner(System.in);
System.out.print("請輸入3個整數(shù)");
int?a?=?s.nextInt();
int?b?=?s.nextInt();
int?c?=?s.nextInt();
if?(a??b)?{
temp?=?a;
a?=?b;
b?=?temp;
}
if?(a??c)?{
temp?=?a;
a?=?c;
c?=?temp;
}
if?(b??c)?{
temp?=?b;
b?=?c;
c?=?temp;
}
System.out.println("a的值:"?+?a?+?"b的值:"?+?b?+?"c的值:"?+?c);
}
}
第二題:
import?java.util.Scanner;
/**
*?Created?by?Chen?on?2015/11/11.
*/
public?class?T?{
public?static?void?main(String[]?args)?{
int?temp?=?0;
Scanner?s?=?new?Scanner(System.in);
System.out.print("輸入一個數(shù)");
int?a?=?s.nextInt();
if((a%3==0)||(a%5==0))
System.out.println("該整數(shù)是3或5的倍數(shù)");
else??System.out.println("“該數(shù)不能被3或5中的任何一個數(shù)整除"?);
}
}
第三題:
import?java.util.Scanner;
/**
*?Created?by?Chen?on?2015/11/11.
*/
public?class?T?{
public?static?void?main(String[]?args)?{
int?price?=?5000;
Scanner?s?=?new?Scanner(System.in);
System.out.print("輸入訂票月份:");
int?month?=?s.nextInt();
if?(month??0??month??13)?{
if?(month??3??month??11)?{
System.out.println("該月車票價格如下:頭等艙"?+?price?*?0.9?+?"元"?+?"??"?+?"經(jīng)濟艙"?+?price?*?0.8);
}?else?System.out.println("該月車票價格如下:頭等艙"?+?price?*?0.5?+?"元"?+?"??"?+?"經(jīng)濟艙"?+?price?*?0.4);
}?else?System.out.println("請輸入正確的月份");
}
}
在你的基礎(chǔ)上稍稍改動:
import java.util.Scanner;
public class JiPiao {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請輸入您要出行的月份:");
int YueFen = input.nextInt();
System.out.println("請問您選擇頭等艙還是經(jīng)濟艙?頭等艙輸入1,經(jīng)濟艙輸入2");
int XuanZe = input.nextInt();
if (XuanZe == 1 || XuanZe == 2) {
} else {
System.out.println("請輸入數(shù)字1,2");
}
double JiaGe;
if (YueFen = 10 YueFen = 4) {
if (XuanZe == 1) {
JiaGe = 5000 * 0.9;
System.out.println("機票的價格為:" + JiaGe);
} else if (XuanZe == 2) {
JiaGe = 5000 * 0.8;
System.out.println("機票的價格為:" + JiaGe);
} else {
System.out.println("輸入錯誤");
}
} else if (YueFen = 1 YueFen = 3 || YueFen == 11 || YueFen == 12) {
if (XuanZe == 1) {
JiaGe = 5000 * 0.5;
System.out.println("機票的價格為:" + JiaGe);
} else if (XuanZe == 2) {
JiaGe = 5000 * 0.4;
System.out.println("機票的價格為:" + JiaGe);
} else {
System.out.println("輸入錯誤");
}
}
}
}
public class Ticket {
private int month;
private int classLevel; //1: 頭等艙, 2: 經(jīng)濟艙
private int price;
private int basePrice = 5000; //原價
public Ticket(int month, int classLevel) {
this.month = month;
this.classLevel = classLevel;
}
public void showMeThePrice() {
//旺季月份: 4-10
if ((month = 4) (month = 10)) {
if (classLevel == 1) {
price = basePrice * 0.9;
System.out.println("Month: " + month + "; Class: " + classLevel + "; Price: " + price);
} else if (classLevel == 2) {
price = basePrice * 0.8;
System.out.println("Month: " + month + "; Class: " + classLevel + "; Price: " + price);
}
}
// 淡季月份: 1,2,3,11,12
if ((month = 1) (month = 3) || month = 11 || month = 12) {
if (classLevel == 1) {
price = basePrice * 0.5;
System.out.println("Month: " + month + "; Class: " + classLevel + "; Price: " + price);
} else if (classLevel == 2) {
price = basePrice * 0.4;
System.out.println("Month: " + month + "; Class: " + classLevel + "; Price: " + price);
}
}
}
}
測試類:
public class Test {
Ticket myTicket = new Ticket(4, 1); //例如:四月,頭等艙
myTicket.showMeThePrice();//輸出顯示價格
...
}
以上代碼全部手打,因為公司沒有安裝jdk,所以無法測試,你自己調(diào)試吧。
嘗試解答一下,這個里面還有老年和教師的判斷就省略,主要是打折的代碼
import?java.util.Scanner;
class?Test{
public?static?void?main?(String[]?args){
Scanner?sc?=?new?Scanner(System.in);
System.out.println("請輸入消費的金額:");
double?oldprice?=?sc.nextDouble();
double?newprice;
if(oldprice?=?2000){
newprice?=?oldprice?*?0.85;
}else?if(oldprice?=?1000??oldprice??2000){
newprice?=?oldprice?*?0.9;
}else
newprice?=?oldprice;
Judge?jud?=?new?Judge();
if(jud.isTeacher()||?jud.isOldman())
newprice?=?newprice?*?0.95;
System.out.println("打折后的價格是:"?+?newprice);
System.out.println("折扣的程度是:?"?+?newprice?/?oldprice);
}
}
class?Judge{
public?boolean?isTeacher(){
boolean?isTeacher?=?false;
return?isTeacher;
}
public?boolean?isOldman(){
boolean?isOld?=?false;
return?isOld;
}
}