網頁

2015年10月16日 星期五

ex4 輸入出生年份,輸出生肖

 輸入出生年份,輸出生肖

參考解答:

27 則留言:

  1. import java.util.Scanner;

    public class aa {

    public static void main(String[] args) {
    int x,y;
    Scanner input=new Scanner(System.in);
    System.out.print("輸入出生年");
    x=input.nextInt();
    y=(x-1600)%12;
    if(y==0)
    System.out.print("鼠");
    else if(y==1)
    System.out.print("牛");
    else if(y==2)
    System.out.print("虎");
    else if(y==3)
    System.out.print("兔");
    else if(y==4)
    System.out.print("龍");
    else if(y==5)
    System.out.print("蛇");
    else if(y==6)
    System.out.print("馬");
    else if(y==7)
    System.out.print("羊");
    else if(y==8)
    System.out.print("猴");
    else if(y==9)
    System.out.print("雞");
    else if(y==10)
    System.out.print("狗");
    else if(y==11)
    System.out.print("豬");
    }
    }

    回覆刪除
  2. import java.util.Scanner;

    public class ex01 {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int x; int r;
    Scanner input=new Scanner (System.in);
    System.out.print("出生年份");
    x=input.nextInt();
    r=(x-1960)%12;
    r=(r+12)%12;
    if(r==0)
    System.out.print("生肖鼠");
    else if(r==1)
    System.out.print("生肖牛") ;
    else if(r==2)
    System.out.print("生肖虎") ;
    else if(r==3)
    System.out.print("生肖兔") ;
    else if(r==4)
    System.out.print("生肖龍") ;
    else if(r==5)
    System.out.print("生肖蛇") ;
    else if(r==6)
    System.out.print("生肖馬") ;
    else if(r==7)
    System.out.print("生肖羊") ;
    else if(r==8)
    System.out.print("生肖猴") ;
    else if(r==9)
    System.out.print("生肖雞") ;
    else if(r==10)
    System.out.print("生肖狗") ;
    else
    System.out.print("生肖豬") ;

    }

    }

    回覆刪除
  3. import java.util.Scanner;

    public class c1 {

    public static void main(String[] args) {
    int x, j;
    Scanner input =new Scanner(System.in);
    System.out.println("請輸入(西元)年號");
    x=input.nextInt();
    j=(x-1960)%12;
    System.out.println("生肖");
    if(j==0)
    System.out.println("鼠");
    if(j==1)
    System.out.println("牛");
    if(j==2)
    System.out.println("虎");
    if(j==3)
    System.out.println("兔");
    if(j==4)
    System.out.println("龍");
    if(j==5)
    System.out.println("蛇");
    if(j==6)
    System.out.println("馬");
    if(j==7)
    System.out.println("羊");
    if(j==8)
    System.out.println("猴");
    if(j==9)
    System.out.println("雞");
    if(j==10)
    System.out.println("狗");
    if(j==11)
    System.out.println("豬");

    }

    }

    回覆刪除
  4. import java.util.Scanner;

    public class h14 {

    public static void main(String[] args) {
    int x,j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    x=input.nextInt();
    j=((x-1960)+12)%12;
    if (j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else
    System.out.println("豬");
    }

    }

    回覆刪除
  5. import java.util.Scanner;

    public class house1016 {

    public static void main(String[] args) {
    int x, j;
    Scanner input =new Scanner(System.in);
    System.out.println("年號");
    x=input.nextInt();
    j=(x-1960)%12;
    System.out.println("生肖");
    if(j==0)
    System.out.println("鼠");
    if(j==1)
    System.out.println("牛");
    if(j==2)
    System.out.println("虎");
    if(j==3)
    System.out.println("兔");
    if(j==4)
    System.out.println("龍");
    if(j==5)
    System.out.println("蛇");
    if(j==6)
    System.out.println("馬");
    if(j==7)
    System.out.println("羊");
    if(j==8)
    System.out.println("猴");
    if(j==9)
    System.out.println("雞");
    if(j==10)
    System.out.println("狗");
    if(j==11)
    System.out.println("豬");

    }

    }

    回覆刪除
  6. import java.util.*;

    public class ex1 {

    public static void main(String[] args) {
    int x, j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    x=input.nextInt();
    j=((x-1960+12)%12);
    if (j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else
    System.out.println("豬");
    }

    }

    回覆刪除
  7. import java.util.Scanner;


    public class e19 {

    public static void main(String[] args) {
    int x,y;
    Scanner input=new Scanner(System.in);
    System.out.println("出生年份");
    x=input.nextInt();
    y=((x-1960)+12)%12;
    if(y==0)
    System.out.println("鼠");
    else if(y==1)
    System.out.println("牛");
    else if(y==2)
    System.out.println("虎");
    else if(y==3)
    System.out.println("兔");
    else if(y==4)
    System.out.println("龍");
    else if(y==5)
    System.out.println("蛇");
    else if(y==6)
    System.out.println("馬");
    else if(y==7)
    System.out.println("羊");
    else if(y==8)
    System.out.println("猴");
    else if(y==9)
    System.out.println("雞");
    else if(y==10)
    System.out.println("狗");
    else
    System.out.println("豬");
    }

    }

    回覆刪除
  8. import java.util.Scanner;

    public class ex_01 {

    public static void main(String[] args) {
    int x,j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    x=input.nextInt();
    j=((x-1960)+12)%12;
    if (j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else if (j==11)
    System.out.println("豬");
    }
    }

    回覆刪除
  9. import java.util.Scanner;

    public class ex_01 {

    public static void main(String[] args) {
    int x,j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    x=input.nextInt();
    j=((x-1960)+12)%12;
    if (j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else if (j==11)
    System.out.println("豬");
    }
    }

    回覆刪除
  10. import java.util.Scanner;

    public class ex1016 {

    public static void main(String[] args) {
    int x,j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    x=input.nextInt();
    j=((x-1960)+12)%12;
    if (j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else if (j==11)
    System.out.println("豬");



    }

    }

    回覆刪除
  11. import java.util.Scanner;
    public class ex1016 {

    public static void main(String[] args) {
    int x,j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    x=input.nextInt();
    j=((x-1960)+12)%12;
    if(j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else if (j==11)
    System.out.println("豬");
    }

    }

    回覆刪除
  12. import java.util.Scanner;

    public class vghj858 {

    public static void main(String[] args) {
    int x,y;
    Scanner input=new Scanner(System.in);
    System.out.print("給我你的出生年份");
    x=input.nextInt();
    y=(x-1192)%12;
    if (y==0)System.out.print("mouse");
    else if (y==1)System.out.print("cow");
    else if (y==2)System.out.print("tiger");
    else if (y==3)System.out.print("rabbit");
    else if (y==4)System.out.print("dragon");
    else if (y==5)System.out.print("snake");
    else if (y==6)System.out.print("horse");
    else if (y==7)System.out.print("goat");
    else if (y==8)System.out.print("monkey");
    else if (y==9)System.out.print("chicken");
    else if (y==10)System.out.print("dog");
    else if (y==11)System.out.print("PIG");
    }
    }

    回覆刪除
  13. import java.util.Scanner;
    public class ex1 {
    public static void main(String[] args) {
    Scanner input=new Scanner(System.in);
    System.out.print("出生年:");
    int x=input.nextInt();
    int r;
    r=(x-1960)%12;
    r=(r+12)%12;
    if (r==0) System.out.print("鼠年");
    else if (r==1) System.out.print("牛年");
    else if (r==2) System.out.print("虎年");
    else if (r==3) System.out.print("兔年");
    else if (r==4) System.out.print("龍年");
    else if (r==5) System.out.print("蛇年");
    else if (r==6) System.out.print("馬年");
    else if (r==7) System.out.print("羊年");
    else if (r==8) System.out.print("猴年");
    else if (r==9) System.out.print("雞年");
    else if (r==10) System.out.print("狗年");
    else if (r==11) System.out.print("豬年");
    }
    }

    回覆刪除
  14. import java.util.Scanner;

    public class happy2 {

    public static void main(String[] args) {
    int x,y;
    Scanner input=new Scanner(System.in);
    System.out.print("出生年份");
    x=input.nextInt();
    y=(x-1960)%12;
    if (y==0)System.out.print("鼠");
    else if (y==1)System.out.print("牛");
    else if (y==2)System.out.print("虎");
    else if (y==3)System.out.print("兔");
    else if (y==4)System.out.print("龍");
    else if (y==5)System.out.print("蛇");
    else if (y==6)System.out.print("馬");
    else if (y==7)System.out.print("羊");
    else if (y==8)System.out.print("猴");
    else if (y==9)System.out.print("雞");
    else if (y==10)System.out.print("狗");
    else if (y==11)System.out.print("豬");
    }
    }

    回覆刪除
  15. import java.util.Scanner;

    public class vghj858 {

    public static void main(String[] args) {
    int x,y;
    Scanner input=new Scanner(System.in);
    System.out.print("給我你的出生年份");
    x=input.nextInt();
    y=(x-1192)%12;
    if (y==0)System.out.print("mouse");
    else if (y==1)System.out.print("cow");
    else if (y==2)System.out.print("tiger");
    else if (y==3)System.out.print("rabbit");
    else if (y==4)System.out.print("dragon");
    else if (y==5)System.out.print("snake");
    else if (y==6)System.out.print("horse");
    else if (y==7)System.out.print("goat");
    else if (y==8)System.out.print("monkey");
    else if (y==9)System.out.print("chicken");
    else if (y==10)System.out.print("dog");
    else if (y==11)System.out.print("PIG");
    }
    }

    回覆刪除
  16. import java.util.Scanner;

    public class vghj858 {

    public static void main(String[] args) {
    int x,y;
    Scanner input=new Scanner(System.in);
    System.out.print("給我你的出生年份");
    x=input.nextInt();
    y=(x-1192)%12;
    if (y==0)System.out.print("mouse");
    else if (y==1)System.out.print("cow");
    else if (y==2)System.out.print("tiger");
    else if (y==3)System.out.print("rabbit");
    else if (y==4)System.out.print("dragon");
    else if (y==5)System.out.print("snake");
    else if (y==6)System.out.print("horse");
    else if (y==7)System.out.print("goat");
    else if (y==8)System.out.print("monkey");
    else if (y==9)System.out.print("chicken");
    else if (y==10)System.out.print("dog");
    else if (y==11)System.out.print("PIG");
    }
    }

    回覆刪除
  17. import java.util.Scanner;

    public class e029 {


    public static void main(String[] args) {
    int x,y;
    Scanner input=new Scanner(System.in);
    System.out.println("出生年份");
    x=input.nextInt();
    y=((x-1960)+12)%12;
    if(y==0)
    System.out.println("鼠");
    else if(y==1)
    System.out.println("牛");
    else if(y==2)
    System.out.println("虎");
    else if(y==3)
    System.out.println("兔");
    else if(y==4)
    System.out.println("龍");
    else if(y==5)
    System.out.println("蛇");
    else if(y==6)
    System.out.println("馬");
    else if(y==7)
    System.out.println("羊");
    else if(y==8)
    System.out.println("猴");
    else if(y==9)
    System.out.println("雞");
    else if(y==10)
    System.out.println("狗");
    else
    System.out.println("豬");

    回覆刪除
  18. import java.util.Scanner;
    public class A10433043 {

    public static void main(String[] args) {
    int X,j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    X=input.nextInt();
    j=((X-1960)+12)%12;
    if(j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else if (j==11)
    System.out.println("豬");
    }
    }

    回覆刪除
  19. import java.util.Scanner;
    public class A10433043 {

    public static void main(String[] args) {
    int X,j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    X=input.nextInt();
    j=((X-1960)+12)%12;
    if(j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else if (j==11)
    System.out.println("豬");
    }
    }

    回覆刪除
  20. import java.util.Scanner;
    public class A10433043 {

    public static void main(String[] args) {
    int X,j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    X=input.nextInt();
    j=((X-1960)+12)%12;
    if(j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else if (j==11)
    System.out.println("豬");
    }
    }

    回覆刪除
  21. import java.util.Scanner;
    public class A10433043 {

    public static void main(String[] args) {
    int X,j;
    Scanner input=new Scanner(System.in);
    System.out.println("請輸入年份");
    X=input.nextInt();
    j=((X-1960)+12)%12;
    if(j==0)
    System.out.println("鼠");
    else if (j==1)
    System.out.println("牛");
    else if (j==2)
    System.out.println("虎");
    else if (j==3)
    System.out.println("兔");
    else if (j==4)
    System.out.println("龍");
    else if (j==5)
    System.out.println("蛇");
    else if (j==6)
    System.out.println("馬");
    else if (j==7)
    System.out.println("羊");
    else if (j==8)
    System.out.println("猴");
    else if (j==9)
    System.out.println("雞");
    else if (j==10)
    System.out.println("狗");
    else if (j==11)
    System.out.println("豬");
    }
    }

    回覆刪除
  22. import java.util.Scanner;

    public class ex {

    public static void main(String[] args) {

    Scanner z =new Scanner(System.in );
    System.out.print("輸入出生年份:");
    int b=z.nextInt();
    int x ;
    x=(b-100)%12;
    if (x==0) System.out.print("鼠");
    else if (x==1) System.out.print("牛");
    else if (x==2) System.out.print("虎");
    else if (x==3) System.out.print("兔");
    else if (x==4) System.out.print("龍");
    else if (x==5) System.out.print("蛇");
    else if (x==6) System.out.print("馬");
    else if (x==7) System.out.print("羊");
    else if (x==8) System.out.print("猴");
    else if (x==9) System.out.print("雞");
    else if (x==10) System.out.print("狗");
    else if (x==11) System.out.print("豬");

    }

    回覆刪除
  23. import java.util.Scanner;
    public class Ex01166 {

    public static void main(String[] args) {
    Scanner z=new Scanner(System.in);
    System.out.print("輸入出生年份:");
    int b=z.nextInt();
    int x;
    x=(b-1960)%12;
    if(x==0)System.out.print("鼠");
    else if(x==1)System.out.print("牛");
    else if(x==2)System.out.print("虎");
    else if(x==3)System.out.print("兔");
    else if(x==4)System.out.print("龍");
    else if(x==5)System.out.print("蛇");
    else if(x==6)System.out.print("馬");
    else if(x==7)System.out.print("羊");
    else if(x==8)System.out.print("猴");
    else if(x==9)System.out.print("雞");
    else if(x==10)System.out.print("狗");
    else if(x==11)System.out.print("豬");
    }

    }

    回覆刪除
  24. import java.util.Scanner;

    public class a123 {

    public static void main(String[] args) {

    System.out.print("出生年份");
    Scanner input=new Scanner(System.in);
    int x=input.nextInt();
    x=(x-1960)%12;
    if(x<0) x+=12;
    String xx="鼠牛虎兔龍蛇馬羊猴雞狗豬";
    System.out.println(xx.charAt(x));
    }

    }

    回覆刪除
  25. package jimmy;

    import java.util.Scanner;

    public class good {

    public static void main(String[] args) {
    Scanner a =new Scanner(System.in);
    System.out.print("輸入出生年份:");
    int b= a.nextInt();
    int c; c=(b-1960)%12;
    if (c==0)System.out.print("鼠");
    else if(c==1)System.out.print("牛");
    else if(c==2)System.out.print("虎");
    else if(c==3)System.out.print("兔");
    else if(c==4)System.out.print("龍");
    else if(c==5)System.out.print("蛇");
    else if(c==6)System.out.print("馬");
    else if(c==7)System.out.print("羊");
    else if(c==8)System.out.print("侯");
    else if(c==9)System.out.print("雞");
    else if(c==10)System.out.print("狗");
    else if(c==11)System.out.print("豬");

    回覆刪除
  26. package jimmy;

    import java.util.Scanner;

    public class good {

    public static void main(String[] args) {
    Scanner a =new Scanner(System.in);
    System.out.print("輸入出生年份:");
    int b= a.nextInt();
    int c; c=(b-1960)%12;
    if (c==0)System.out.print("鼠");
    else if(c==1)System.out.print("牛");
    else if(c==2)System.out.print("虎");
    else if(c==3)System.out.print("兔");
    else if(c==4)System.out.print("龍");
    else if(c==5)System.out.print("蛇");
    else if(c==6)System.out.print("馬");
    else if(c==7)System.out.print("羊");
    else if(c==8)System.out.print("侯");
    else if(c==9)System.out.print("雞");
    else if(c==10)System.out.print("狗");
    else if(c==11)System.out.print("豬");




    }


    }

    回覆刪除
  27. package jimmy;

    import java.util.Scanner;

    public class good {

    public static void main(String[] args) {
    Scanner a =new Scanner(System.in);
    System.out.print("輸入出生年份:");
    int b= a.nextInt();
    int c; c=(b-1960)%12;
    if (c==0)System.out.print("鼠");
    else if(c==1)System.out.print("牛");
    else if(c==2)System.out.print("虎");
    else if(c==3)System.out.print("兔");
    else if(c==4)System.out.print("龍");
    else if(c==5)System.out.print("蛇");
    else if(c==6)System.out.print("馬");
    else if(c==7)System.out.print("羊");
    else if(c==8)System.out.print("侯");
    else if(c==9)System.out.print("雞");
    else if(c==10)System.out.print("狗");
    else if(c==11)System.out.print("豬");




    }


    }

    回覆刪除

HTML 編輯器