首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >类分配数值报告Java代码

类分配数值报告Java代码
EN

Stack Overflow用户
提问于 2017-03-02 23:51:42
回答 1查看 1.1K关注 0票数 0

写一个程序,将一个人的出生日期数字相加,以获得一个数字,以生成命理报告。

下面是我的代码,它大部分是完整的,但是我不知道它是否正确,因为当我试图编译它时,在第一次编译后,我得到了一个错误消息,我需要一个';‘,但当我添加;时,它只会给我更多的错误。感谢您的帮助,谢谢!

import java.util.Scanner;

public class rneely_Numerology {

    public static void main (String args [])
    {
        int date = 0;
        int sum;
        int day = 0;
        int month = 0;
        int year = 0;
        int numerology = 0;
        int tempnumerology = 0;
        char A;
        char B;
        int leapyear = 0;

        leapyear = year % 4;

        Scanner input = new Scanner (System.in);

        do {
            System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
            month = input.nextInt();
            A = input.next().charAt(0);
            day = input.nextInt();
            B = input.next().charAt(0);
            year = input.nextInt();
        }
        while (month < 1 || month > 12)
            {
                System.out.printf ( "Bad month: %d\n", month);
                System.out.println();
                System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 );
            {
                if (day < 1 || day > 31)
                {
                    System.out.printf ( "Bad day: %d\n", day);
                    System.out.println();
                }
                System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                                                                                   B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (month == 4 || month == 6 || month == 9 || month == 11);
            {
                if (day < 1 || day > 30)
                {
                    System.out.printf ( "Bad day: %d\n", day);
                    System.out.println();
                }

                System.out.print ( "Enter the birth day (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (month == 2);
            {
                if (year % 400 = 0) {
                    if (year % 100 = 0) {}}
                else if (year % 4 = 0)
                {
                    if (day < 1 || day > 29)
                    {
                        System.out.printf ( "Bad day for %d%d: %d\n", month, year, day);
                        System.out.println();
                    }
                }
                else
                {
                    if (day < 1 || day > 28)
                    {
                        System.out.printf ( "Bad day for %d%d: %d\n", month, year, day);
                        System.out.println();
                    }
                }

                System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (year < 1880 || year > 2280);
            {
                System.out.printf ( "Bad year: %d\n", year);
                System.out.println();
                            System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (A != '/' || B != '/');

            System.out.print ( "Use forward slashes between month, day, and year!\n" );
            System.out.println();
            System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
            month = input.nextInt();
            A = input.next().charAt(0);
            day = input.next.Int();
            B = input.next().charAt(0);
            year = input.nextInt();



            date = month + day + year;
            for ( int numerology = date; numerology <= 9; numerology %= 10 ) {
                date = numerology;
            }

            System.out.printf ( "Welcome to the numerology report for %d/%d/%d\n", month, day, year);

            switch (numerology)
            {
                case 1:
                    System.out.println ( "-1- Hard work pays off in the future, laziness pays off now. ");
                    break;
                case 2:
                    System.out.println ( "-2- You learn from your mistakes... you will learn a lot today. ");
                    break;
                case 3:
                    System.out.println ( "-3- Your high minded principles spell success. ");
                    break;
                case 4:
                    System.out.println ( "-4- A dream you have will come true. ");
                    break;
                case 5:
                    System.out.println ( "-5- The greatest risk is not taking one. ");
                    break;
                case 6:
                    System.out.println ( "-6- Your ability for accomplishment will follow with success. ");
                    break;
                case 7:
                    System.out.println ( "-7- You will travel to many exotic places in your lifetime. ");
                    break;
                case 8:
                     System.out.println ( "-8- Keep your eye out for someone special. ");
                    break;
                case 9:
                    System.out.println ( "-9- Now is the time to try something new. ");
                    break;
            }
        }

    }
EN

回答 1

Stack Overflow用户

发布于 2017-03-03 00:28:47

所遵循的语法不正确。请在下面找到一个修正后的程序。

import java.util.Scanner;

public class Numerology {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        do {
            System.out.println("Enter the birth date (mm/dd/yyyy): ");
            String inp = input.nextLine();
            Integer month = null;
            Integer day = null;
            Integer year = null;
            try {
                String[] inpArr = inp.split("/");
                month = Integer.parseInt(inpArr[0]);
                day = Integer.parseInt(inpArr[1]);
                year = Integer.parseInt(inpArr[2]);
            } catch (Exception e) {
                System.out.println("Use forward slashes between month, day, and year!");
                continue;
            }
            String[] inpArr = inp.split("/");

            if (month < 1 || month > 12) {
                System.out.println("Bad Month : " + month);
                continue;
            }

            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                if (day < 1 || day > 31) {
                    System.out.println("Bad day: " + day);
                    continue;
                }
            } else if (month == 2) {
                if (year % 4 == 0) {
                    if (day < 1 || day > 29) {
                        System.out.println("Bad day: " + day);
                        continue;
                    }
                } else {
                    if (day < 1 || day > 28) {
                        System.out.println("Bad day: " + day);
                        continue;
                    }
                }
            } else {
                if (day < 1 || day > 30) {
                    System.out.println("Bad day: " + day);
                    continue;
                }
            }

            if (year < 1880 || year > 2280) {
                System.out.println("Bad year: " + year);
                continue;
            }

            String date = (month + day + year) + "";

            int sum = 11;
            while (sum > 10) {
                sum = 0;
                String[] dateArr = date.split("");
                for (int i = 0; i < dateArr.length; i++) {
                    sum += Integer.parseInt(dateArr[i]);
                }
                date = sum + "";
            }

            switch (sum) {
            case 1:
                System.out.println("-1- Hard work pays off in the future, laziness pays off now. ");
                break;
            case 2:
                System.out.println("-2- You learn from your mistakes... you will learn a lot today. ");
                break;
            case 3:
                System.out.println("-3- Your high minded principles spell success. ");
                break;
            case 4:
                System.out.println("-4- A dream you have will come true. ");
                break;
            case 5:
                System.out.println("-5- The greatest risk is not taking one. ");
                break;
            case 6:
                System.out.println("-6- Your ability for accomplishment will follow with success. ");
                break;
            case 7:
                System.out.println("-7- You will travel to many exotic places in your lifetime. ");
                break;
            case 8:
                System.out.println("-8- Keep your eye out for someone special. ");
                break;
            case 9:
                System.out.println("-9- Now is the time to try something new. ");
                break;
            }
            break;
        } while (true);
        input.close();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42559959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档