Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Java/Program-8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Q. Java Program to Find if a Given Year is a Leap Year.


Leap Year contains 366 days, which comes once every four years. Every leap year corresponds to these facts :

#A century year is a year ending with 00. A century year is a leap year only if it is divisible by 400.
#A leap year (except a century year) can be identified if it is exactly divisible by 4.
#A century year should be divisible by 4 and 100 both.
#A non-century year should be divisible only by 4.


Ex.
INPUT: 2000
OUTPUT: 2000 : Leap-year
LOGIC: 2000 is a century year divisible by 100 and 4.
INPUT: 2002
OUTPUT: 2002 : Non Leap-year
LOGIC: 2002 is not divisible by 4, therefore not a leap year.
66 changes: 66 additions & 0 deletions Java/Program-8/program.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Java program to find a leap year

// Importing Classes/Files
import java.io.*;

// Class for leap-year dealing
public class GeeksforGeeks {

// Method to check leap year
public static void isLeapYear(int year)
{
// flag to take a non-leap year by default
boolean is_leap_year = false;

// If year is divisible by 4
if (year % 4 == 0) {

// To identify whether it
// is a century year or
// not
if (year % 100 == 0) {

// Checking if year is divisible by 400
// therefore century leap year
if (year % 400 == 0) {
is_leap_year = true;
}

else {
is_leap_year = false;
}
}

// Out of if loop that is Non century year
// but divisible by 4, therefore leap year
is_leap_year = true;
}

// We land here when corresponding if fails
// If year is not divisible by 4
else

// Flag dealing- Non leap-year
is_leap_year = false;

if (!is_leap_year) {
System.out.println(year + " : Non Leap-year");
}

else {
System.out.println(year + " : Leap-year");
}
}

// Main Driver Code
public static void main(String[] args)
{
// Calling our function by
// passing century year
isLeapYear(2000);

// Calling our function by
// passing Non-century year
isLeapYear(2002);
}
}
21 changes: 21 additions & 0 deletions Java/program-9/README.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Q. Java Program to Check If a Number is Neon Number or Not

A neon number is a number where the sum of digits of the square of the number is equal to the number.
The task is to check and print neon numbers in a range.

Case 1:

Input : 9
Output : Given number 9 is Neon number

Explanation : square of 9=9*9=81;
sum of digit of square : 8+1=9(which is equal to given number)


Case 2:

Input : 8
Output : Given number is not a Neon number

Explanation : square of 8=8*8=64
sum of digit of square : 6+4=10(which is not equal to given number)
64 changes: 64 additions & 0 deletions Java/program-9/program.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Java Program to Check If a Number is Neon number or not

// Importing java input/output library
import java.io.*;

class GFG {

// Method to check whether number is neon or not
// Boolean type
public static boolean checkNeon(int n)
{
// squarring the number to be checked
int square = n * n;

// Initializing current sum to 0
int sum = 0;

// If product is positive
while (square > 0) {

// Step 1: Find remainder
int r = square % 10;

// Add remainder to the current sum
sum += r;

// Drop last digit of the product
// and store the number
square = square / 10;
}

// Condition check
// Sum of digits of number obtained is
// equal to original number
if (sum == n)

// number is neon
return true;
else

// numbe is not neon
return false;
}

// Main driver method
public static void main(String[] args)
{
// Custom input
int n = 9;

// Calling above function to check custom number or
// if user entered number via Scanner class
if (checkNeon(n))

// Print number considered is neon
System.out.println("Given number " + n
+ " is Neon number");
else

// Print number considered is not neon
System.out.println("Given number " + n
+ " is not a Neon number");
}
}