這個題可以使用switch-case語句來解決,首先創(chuàng)建簡單文本掃描器,然后從鍵盤讀入0~9或字母a,然后通過開關(guān)語句進(jìn)行匹配,進(jìn)而輸出結(jié)果,代碼如下:
常熟ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
在main()方法中調(diào)用,在控制臺輸入,驗(yàn)證輸出,效果如下:
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class xingzuo extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException { res.setContentType("text/html"); res.setCharacterEncoding("GB2312"); PrintWriter out = res.getWriter(); String getmonth = req.getParameter("month"); int month = new Integer(getmonth).intValue(); String getday = req.getParameter("day"); int day = new Integer(getday).intValue(); String test=req.getParameter("T1"); boolean err=false; int xingzuonumber=0; int fenjie[]={21,19,21,21,22,22,23,24,24,24,23,22}; int zuida[]={31,29,31,30,31,30,31,31,30,31,30,31}; String xingzuo[]={"水平座","雙魚座","白羊座","金牛座","雙子座","巨蟹座","獅子座","處女座","天秤座","天蝎座","人馬座","山羊座"}; String xingge[]=new String[12]; xingge[0]="這個星座常被稱為'天才星座'或'未來星座'。"; xingge[7]="處女座的特色是有豐富的知性,做事一絲不茍,"; xingge[8]="天秤座的人愛好美與和諧,也相當(dāng)仁慈并富有同情心,"; xingge[9]="這個星座的人有著強(qiáng)烈的第六感、神秘的探視能力及吸引力,"; xingge[10]="這個星座出生的人崇尚自由、無拘無束及追求速度的感覺,"; xingge[11]="就像是只走在高山絕壁的山羊一樣穩(wěn)健踏實(shí),"; out.print("html"); out.print("body bgcolor=#3300ff"); out.print("center"); if(zuida[month-1]day) { err=true; }; if(day= fenjie[month-1]) { xingzuonumber=(month%12)+1; }else{xingzuonumber=month;}; if (err) { out.print("您輸入的生日有錯誤,請重新輸入"); }else{ out.print("table border=1"+"tr"); out.print("td"); out.print("img src = 'image/"+ xingzuonumber + ".jpg'/td"); out.print("td"); out.print("您的生日是"+month+"月"+day+"日"+"您的星座是"+xingzuo[(xingzuonumber+10)%12]+"這個星座的特點(diǎn)是:"+xingge[(xingzuonumber+10)%12]+"font color=reda href = xingzuo.jsp點(diǎn)擊返回首頁"); } //out.print(xingzuo[0]); out.print("/tr/table/center"); out.print("/body"); out.print("/html"); } }
經(jīng)過一定的選擇過后會羅列出一大段運(yùn)勢數(shù)據(jù),而這些是按一定次序進(jìn)行羅列出來的.
設(shè)置一組數(shù)字矩陣,矩陣中每個數(shù)字都對應(yīng)于一項(xiàng)星辰運(yùn)勢
每個星座可以設(shè)置多個選項(xiàng),除了星座選擇外,還可以根據(jù)相同星座的不同日期段(如0號到3號,3號到6號.....),以及血型(o,a,b...)或者屬相(鼠,牛,虎....)
舉例:
數(shù)據(jù)假設(shè)分四類,一日期,二血型,三屬相,四星座
日期 a1,a2,a3,a4....
血型 b1,b2,b3,b4....
屬相 c1,c2,c3,c4....
星座 d1,d2,d3,d4....
獲取數(shù)據(jù)用戶輸入信息,如a2,b3,c1,d2
從而獲取對應(yīng)位置的數(shù)據(jù)存儲地址,從地址讀出數(shù)據(jù)并顯示
可以對用戶輸入信息做一定的運(yùn)算,根據(jù)前后數(shù)據(jù)的關(guān)系,如輸出信息分四部分,分別為y1=f(abcx),y2=f(abcx),y3=f(abcx),y4=f(abcx),經(jīng)過一定運(yùn)算后將其特定地址的內(nèi)容顯示出來即可,只要注意處理運(yùn)算超界問題 程序就可以很好的運(yùn)行了
/*注意:請使用較高JAVA版本。
代碼如下:*/
import java.io.*;
import java.util.*;
class Sign
{int x,y,z,n;
public static void main(String[] args) throws IOException
{
Scanner s=new Scanner(System.in);
Sign t=new Sign();
System.out.println("This program determines a person's Zodiac Star Sign and Chinese Animal Sign.");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int count=0;
System.out.print("Would you like to continue? (yes or no):");
String s1=br.readLine();
while(s1.equals("yes")){
System.out.print("Enter the person's full name:");
String s2=br.readLine();
System.out.print("Enter the person's month of birth as an integer between 1 and 12:");
t.x=s.nextInt();
System.out.print("Enter the person's day of birth as an integer between 1 and 31:");
t.y=s.nextInt();
System.out.print("Enter the person's year of birth (eg. 1906, 1968, 2005, etc...):");
t.z=s.nextInt();
System.out.print("Full name:");
System.out.println(s2);
System.out.print("Month of Birth:");
System.out.println(t.x);
System.out.print("Day of Birth:");
System.out.println(t.y);
System.out.print("Year of Birth:");
System.out.println(t.z);
String s3="Wrong!";
switch(t.x){
case 1 :
if(t.y21){s3="Capricorn";break;}
else s3="Aquarius";break;
case 2 :
if(t.y20){s3="Aquarius";break;}
else s3="Pisces";break;
case 3 :
if(t.y21){s3="Pisces";break;}
else s3="Aries";break;
case 4 :
if(t.y21){s3="Aries";break;}
else s3="Taurus";break;
case 5 :
if(t.y22){s3="Taurus";break;}
else s3="Gemini";break;
case 6 :
if(t.y22){s3="Gemini";break;}
else s3="Cancer";break;
case 7 :
if(t.y23){s3="Cancer";break;}
else s3="Leo";break;
case 8 :
if(t.y23){s3="Leo";break;}
else s3="Virgo";break;
case 9 :
if(t.y24){s3="Virgo";break;}
else s3="Libra";break;
case 10:
if(t.y24){s3="Libra";break;}
else s3="Scorpio";break;
case 11:
if(t.y23){s3="Scorpio";break;}
else s3="Sagittarius";break;
case 12:
if(t.y22) {s3="Sagittarius";break;}
else s3="Capricorn";break;}
System.out.print("Zodiac Star Sign:");
System.out.println(s3);
String s4="Wrong!";
t.n=(t.z-700)%12;
switch(t.n){
case 1 :
s4="Ox";break;
case 2 :
s4="Tiger";break;
case 3 :
s4="Rabbit";break;
case 4 :
s4="Dragon";break;
case 5 :
s4="Snake";break;
case 6 :
s4="Horse";break;
case 7 :
s4="Goat";break;
case 8 :
s4="Monkey";break;
case 9 :
s4="Rooster";break;
case 10:
s4="Dog";break;
case 11:
s4="Pig";break;
case 0:
s4="Mouse";break;
}
System.out.print("Chinese Animal Sign:");
System.out.println(s4);
count++;
System.out.print("Would you like to continue? (yes or no):");
s1=br.readLine();
}
System.out.println("Thank you for using this program.");
System.out.println("You determined the Zodiac Star Sign and Chinese Animal Sign of "+count+" person(s).");
}
}
/*PS如果代碼運(yùn)行正常,能否多給幾分。
弄這個東西很辛苦的,如果運(yùn)行不正常,可能是輸入錯誤,其他問題可以聯(lián)系ssfvessfve@163.com*/
既然不允許用其他的方式,那就直接上代碼吧....
public?static?void?main(String[]?args)?{
int?point?=?-1;
String[]?str?=?{"白羊","金牛","雙子","巨蟹","獅子","處女","天平","天蝎","射手","摩羯","水瓶","雙魚"};
SimpleDateFormat?sdf?=?new?SimpleDateFormat("MM-dd");
System.out.println("請輸入一個日期,格式為MM-dd,例如:8-9");
Scanner?scan?=?new?Scanner(System.in);
Date?d?=?null;
while?(true)?{
try?{
String?input?=?scan.next();
d?=?sdf.parse(input);
break;
}?catch?(Exception?ex)?{
System.out.println("請輸入正確的日期格式,例如:08-09");
}
}
//格式化日期,將日期轉(zhuǎn)成**.**的格式,比如1月1日轉(zhuǎn)成1.01
Double?date?=?Double.parseDouble((d.getMonth()?+?1)
+?"."?+?String.format("%02d",?d.getDate()));
if?(3.21?=?date??4.19?=?date)?{
point?=?0;
}?else?if?(4.20?=?date??5.20?=?date)?{
point?=?1;
}?else?if?(5.21?=?date??6.21?=?date)?{
point?=?2;
}?else?if?(6.22?=?date??7.22?=?date)?{
point?=?3;
}?else?if?(7.23?=?date??8.22?=?date)?{
point?=?4;
}?else?if?(8.23?=?date??9.22?=?date)?{
point?=?5;
}?else?if?(9.23?=?date??10.23?=?date)?{
point?=?6;
}?else?if?(10.24?=?date??11.22?=?date)?{
point?=?7;
}?else?if?(11.23?=?date??12.21?=?date)?{
point?=?8;
}?else?if?(12.22?=?date??12.31?=?date)?{
point?=?9;
}?else?if?(1.01?=?date??1.19?=?date)?{
point?=?9;
}?else?if?(1.20?=?date??2.18?=?date)?{
point?=?10;
}?else?if?(2.19?=?date??3.20?=?date)?{
point?=?11;
}
if(point?==?-1)?{
System.out.println("你真的是地球人么....");return;
}
System.out.println(String.format(
"找到啦!o^?^o,你的星座是%s.",?str[point]));
import?java.text.ParseException;
import?java.text.SimpleDateFormat;
import?java.util.Calendar;
import?java.util.Date;
import?java.util.Scanner;
public?class?Test?{
public?static?void?main(String[]?args)?throws?ParseException?{
Scanner?scanner?=?new?Scanner(System.in);
//?只輸入月、日,此代碼未校驗(yàn)月、日輸入是否合理,比如2月30
System.out.print("請輸入你的出生月份");
int?month?=?scanner.nextInt();
System.out.print("請輸入你的出生日期");
int?day?=?scanner.nextInt();
System.out.print("你的星座是:");
//?通過輸入完整日期的方式判斷,可以自動處理不合理日期,比如2月30
//?SimpleDateFormat?dateFormat?=?new?SimpleDateFormat("yyyy-MM-dd");
//?System.out.print("請輸入你的出生日期(形如2018-02-03):");
//?Date?birthday?=?dateFormat.parse(scanner.nextLine());
//
//?Calendar?calendar?=?Calendar.getInstance();
//?calendar.setTime(birthday);
//?int?month?=?calendar.get(Calendar.MONTH)?+?1;
//?int?day?=?calendar.get(Calendar.DAY_OF_MONTH);
//?System.out.print("你的生日是?:"?+?dateFormat.format(birthday)?+?"\r\n你的星座是:");
scanner.close();
switch?(month)?{
case?1:
if?(day??22)
System.out.println("摩羯座");
else
System.out.println("水瓶座");
break;
case?2:
if?(day??22)
System.out.println("水瓶座");
else
System.out.println("雙魚座");
break;
case?3:
if?(day??22)
System.out.println("雙魚座");
else
System.out.println("白羊座");
break;
case?4:
if?(day??22)
System.out.println("白羊座");
else
System.out.println("金牛座");
break;
case?5:
if?(day??22)
System.out.println("金牛座");
else
System.out.println("雙子座");
break;
case?6:
if?(day??22)
System.out.println("雙子座");
else
System.out.println("巨蟹座");
break;
case?7:
if?(day??22)
System.out.println("巨蟹座");
else
System.out.println("獅子座");
break;
case?8:
if?(day??22)
System.out.println("獅子座");
else
System.out.println("處女座");
break;
case?9:
if?(day??22)
System.out.println("處女座");
else
System.out.println("天枰座");
break;
case?10:
if?(day??22)
System.out.println("天枰座");
else
System.out.println("天蝎座");
break;
case?11:
if?(day??22)
System.out.println("天蝎座");
else
System.out.println("射手座");
break;
case?12:
if?(day??22)
System.out.println("射手座");
else
System.out.println("摩羯座");
}
}
}