package 星座
import java.awt.BorderLayout
import java.awt.FlowLayout
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.util.Calendar
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JTextField
public class Constellation implements ActionListener{
private JFrame frame = null
private JTextField year = null
private JTextField month = null
private JTextField day = null
private JLabel label1 = null
private JLabel label2 = null
private JLabel label3 = null
private JPanel panel1 = null
private JPanel panel2 = null
private JButton button = null
private JTextField output = null
public static final String[] zodiacArr = {
import java.text.ParseExceptionimport 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
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("摩羯座")
}
}
}
定义一个String类;使用接收格式为(xx/xx)
使用Stringbuffer分割为两个int类型
month(月) day(日)
switch(month){
case 1:
if(day<=23){
system.out.print("....星座");
}else{
system.out.print("....星座");
}
black;
…………
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)