java判断星座代码 用java编程星座查询
java基础题,关于输入月日来判断星座的,求教
import java.text.ParseException;
我们提供的服务有:成都网站设计、做网站、微信公众号开发、网站优化、网站认证、杨浦ssl等。为成百上千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的杨浦网站制作公司
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版本。
代码如下:*/
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写星座运势,算法怎么写?
经过一定的选择过后会罗列出一大段运势数据,而这些是按一定次序进行罗列出来的.
设置一组数字矩阵,矩阵中每个数字都对应于一项星辰运势
每个星座可以设置多个选项,除了星座选择外,还可以根据相同星座的不同日期段(如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判断星座代码 用java编程星座查询
分享路径:http://ybzwz.com/article/dogosos.html