this is wrong.....Because 100 is not a leap year
Correct logic is
if(year%400 ==0 || (year%100 != 0 && year%4 == 0))
{
printf("Year %d is a leap year",year);
}
import java.util.Scanner;
public class LeapYearOrNot
{
public static void main(String[] args)
{
int n;
System.out.println("Enter the year");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
if (n%4 == 0 && n%100!=0||n%400==0)
{
System.out.println("The given year is a leap year");
}
else
{
System.out.println("This is not a leap year");
}
}
}
hi very thankful to u bcz by this prog i got an idea..
leap yeardinesh kumar girare March 13, 2013 at 12:30 PM
the logic of leap year if(year%4==0)
is perfectly not a correct logic so change these correct logic
if((year%4==0)&&year%100!=0)
{
System.out.println("leap year");
}
else
{
if((year%4==0)&&(year%400==0)&&(year%100==0)
System.out.println("leap year");
else
System.out.println("not leap year");
}
}
so thanks
package prix;
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the year : ");
int n = scanner.nextInt();
if (n%4==0){
System.out.println("Congratz! This is a leap year");
}
else{
System.out.println("This is not a leap year");
}
}
}
wrong programVajrala Rama Rao June 25, 2011 at 8:47 PM
Please verify your program. Logic Is Incorrect.
Bugneeraj September 27, 2011 at 5:06 PM
this is wrong.....Because 100 is not a leap year Correct logic is if(year%400 ==0 || (year%100 != 0 && year%4 == 0)) { printf("Year %d is a leap year",year); }
java Program to find a given year is leap or not? Dinesh November 1, 2011 at 2:30 AM
import java.util.Scanner; public class LeapYearOrNot { public static void main(String[] args) { int n; System.out.println("Enter the year"); Scanner sc = new Scanner(System.in); n = sc.nextInt(); if (n%4 == 0 && n%100!=0||n%400==0) { System.out.println("The given year is a leap year"); } else { System.out.println("This is not a leap year"); } } }
hi,Dni November 1, 2011 at 2:35 AM
hi very thankful to u bcz by this prog i got an idea..
leap yeardinesh kumar girare March 13, 2013 at 12:30 PM
the logic of leap year if(year%4==0) is perfectly not a correct logic so change these correct logic if((year%4==0)&&year%100!=0) { System.out.println("leap year"); } else { if((year%4==0)&&(year%400==0)&&(year%100==0) System.out.println("leap year"); else System.out.println("not leap year"); } } so thanks
javabrycool September 21, 2012 at 7:31 AM
how to create the leap year program in java
The same modified with users own input.Pritam Patra November 25, 2012 at 2:03 AM
package prix; import java.util.Scanner; public class LeapYear { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the year : "); int n = scanner.nextInt(); if (n%4==0){ System.out.println("Congratz! This is a leap year"); } else{ System.out.println("This is not a leap year"); } } }
Post your Comment