ameer
ameer

Reputation: 31

How to execute the codes again

this code is correct but i want to add a message for example "good" if the inputted number is greater than 1520 and less than 3999

import java.util.Scanner;
public class date
{
    public static void main (String args [])
    {
        int x;
        Scanner in = new Scanner (System.in);
        System.out.print("Enter a date ");
        x = in.nextInt();

        while (x < 1520 || x > 3999)
        {
            System.out.println ("Invalid Gregorian Calendar date.");
            System.out.print ("Please Input a valid Gregorian Calendar date: ");
            x = in.nextInt();
        }
    }   
}

Upvotes: 0

Views: 59

Answers (1)

Ricky Mutschlechner
Ricky Mutschlechner

Reputation: 4409

You just have to add a print statement (ie. System.out.println("Good");) after your loop.

*NOTE: I changed the class name from date to Date, which is proper Java convention for naming a Class. Please change your file from date.java to Date.java when you use this code (if you copy and paste it, that is) to prevent compilation issues. Class name and filename must match up, case-sensitive), in Java if I recall correctly.

import java.util.Scanner;

public class Date{
   public static void main (String args []){
      int x;

      Scanner in = new Scanner (System.in);
      System.out.print("Enter a date ");
      x = in.nextInt();


      while (x < 1520 || x > 3999)
      {
          System.out.println ("Invalid Gregorian Calendar date.");
          System.out.print ("Please Input a valid Gregorian Calendar date: ");
          x = in.nextInt();
      }
      System.out.println("Good");
  }
}

Upvotes: 2

Related Questions