Search:

Type: Posts; User: Tjstretch

Search: Search took 0.15 seconds.

  1. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    Ok I got it working with:

    import java.util.Scanner;

    public class BirthdayEdit {

    public static void main (String arg[])
    {
    Scanner sc = new Scanner(System.in);
    boolean cont =...
  2. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    Hmm thats interesting, one second
  3. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    I edited the code that I posted, look at how I did it.
  4. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    Yes, it would do that with the above code, except it would ask
    "Continue?"
    after all that. Run the code and see for yourself
  5. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    As for checking if its not Febuary 30th, add this with all your other validity checks

    else if(birthMonth == 2 && birthDay == 30)
    {
    System.out.println("Invalid day!");
    break;
    }
  6. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    Ok, 2 things. You should change

    int birthMonth = sc.nextInt();
    int birthDay = sc.nextInt();
    int birthYear = (sc.nextInt() - 1900);

    to

    System.out.println("What is your birth month?");...
  7. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    Sorry if I'm getting over your head, I can break all the code down and explain it if you want ;)
    Also, it will make your code look a little less to-the-point, because you have to check everything...
  8. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    Oh, thats what you meant. Just use a while statement and an if statement, like so:

    int birthMonth = sc.nextInt();
    while(birthMonth > 12 || birthMonth < 0)
    {
    System.out.println("Invalid birth...
  9. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    You're Welcome, as to your request:

    Throwing an error:

    throw new AssertionError("Maximum 29 days in Febuary");


    Reviewed your code, you should use a switch statement, then use one println. ...
  10. Replies
    17
    Views
    1,787

    Re: Case Switch Help?

    Thats a very basic mistake, happens to everyone. Change

    int birthMonthAdd;

    to

    int birthMonthAdd = 0;

    It has to do with the compiler not knowing that it will actually get initialized in...
Results 1 to 10 of 10