用java编写星座代码 java星座查询代码
编写一个java程序,实现如下功能?
这个题可以使用switch-case语句来解决,首先创建简单文本扫描器,然后从键盘读入0~9或字母a,然后通过开关语句进行匹配,进而输出结果,代码如下:
常熟ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
在main()方法中调用,在控制台输入,验证输出,效果如下:
怎么用JSP编一个关于星座的程序
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]="天秤座的人爱好美与和谐,也相当仁慈并富有同情心,"; xingge[9]="这个星座的人有著强烈的第六感、神秘的探视能力及吸引力,"; xingge[10]="这个星座出生的人崇尚自由、无拘无束及追求速度的感觉,"; xingge[11]="就像是只走在高山绝壁的山羊一样稳健踏实,"; 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]+"这个星座的特点是:"+xingge[(xingzuonumber+10)%12]+"font color=reda href = xingzuo.jsp点击返回首页"); } //out.print(xingzuo[0]); out.print("/tr/table/center"); out.print("/body"); out.print("/html"); } }
用JAVA写星座运势,算法怎么写?
经过一定的选择过后会罗列出一大段运势数据,而这些是按一定次序进行罗列出来的.
设置一组数字矩阵,矩阵中每个数字都对应于一项星辰运势
每个星座可以设置多个选项,除了星座选择外,还可以根据相同星座的不同日期段(如0号到3号,3号到6号.....),以及血型(o,a,b...)或者属相(鼠,牛,虎....)
举例:
数据假设分四类,一日期,二血型,三属相,四星座
日期 a1,a2,a3,a4....
血型 b1,b2,b3,b4....
属相 c1,c2,c3,c4....
星座 d1,d2,d3,d4....
获取数据用户输入信息,如a2,b3,c1,d2
从而获取对应位置的数据存储地址,从地址读出数据并显示
可以对用户输入信息做一定的运算,根据前后数据的关系,如输出信息分四部分,分别为y1=f(abcx),y2=f(abcx),y3=f(abcx),y4=f(abcx),经过一定运算后将其特定地址的内容显示出来即可,只要注意处理运算超界问题 程序就可以很好的运行了
一个算星座的程序 会的帮下 急用
/*注意:请使用较高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如果代码运行正常,能否多给几分。
弄这个东西很辛苦的,如果运行不正常,可能是输入错误,其他问题可以联系ssfvessfve@163.com*/
用java编一个程序能通过用户输入的生日判断用户的星座。请大神们给点提示或者思路吧。规定不能自定义方法
既然不允许用其他的方式,那就直接上代码吧....
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");
}
}
//格式化日期,将日期转成**.**的格式,比如1月1日转成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]));
java基础题,关于输入月日来判断星座的,求教
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);
// 只输入月、日,此代码未校验月、日输入是否合理,比如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("摩羯座");
}
}
}
本文名称:用java编写星座代码 java星座查询代码
URL标题:http://myzitong.com/article/doddeoi.html