From 93f5b93d51b7931cc5f17ec913e56bea5344ede3 Mon Sep 17 00:00:00 2001 From: mahi252001 Date: Sun, 3 Oct 2021 17:37:10 +0530 Subject: [PATCH 1/3] program8 added --- Java/Program-8/README.md.txt | 18 ++++++++++ Java/Program-8/program.java | 66 ++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 Java/Program-8/README.md.txt create mode 100644 Java/Program-8/program.java diff --git a/Java/Program-8/README.md.txt b/Java/Program-8/README.md.txt new file mode 100644 index 00000000..ae460999 --- /dev/null +++ b/Java/Program-8/README.md.txt @@ -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. \ No newline at end of file diff --git a/Java/Program-8/program.java b/Java/Program-8/program.java new file mode 100644 index 00000000..96baaaef --- /dev/null +++ b/Java/Program-8/program.java @@ -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); + } +} From 0d0c972a90f82f19253ff1f12e754fd1baab37df Mon Sep 17 00:00:00 2001 From: mahi252001 Date: Sun, 3 Oct 2021 18:00:55 +0530 Subject: [PATCH 2/3] Added program-9 --- Java/program-9/README.md.txt | 21 ++++++++++++ Java/program-9/program.java | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Java/program-9/README.md.txt create mode 100644 Java/program-9/program.java diff --git a/Java/program-9/README.md.txt b/Java/program-9/README.md.txt new file mode 100644 index 00000000..c1462f2d --- /dev/null +++ b/Java/program-9/README.md.txt @@ -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) \ No newline at end of file diff --git a/Java/program-9/program.java b/Java/program-9/program.java new file mode 100644 index 00000000..d9940264 --- /dev/null +++ b/Java/program-9/program.java @@ -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"); + } +} From a31b5b8d39c859141b11b0f6c583a25124db0a18 Mon Sep 17 00:00:00 2001 From: Swasthik Shetty <42874695+swaaz@users.noreply.github.com> Date: Sun, 3 Oct 2021 19:57:36 +0530 Subject: [PATCH 3/3] Rename README.md.txt to README.md --- Java/Program-8/{README.md.txt => README.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Java/Program-8/{README.md.txt => README.md} (90%) diff --git a/Java/Program-8/README.md.txt b/Java/Program-8/README.md similarity index 90% rename from Java/Program-8/README.md.txt rename to Java/Program-8/README.md index ae460999..cb140418 100644 --- a/Java/Program-8/README.md.txt +++ b/Java/Program-8/README.md @@ -15,4 +15,4 @@ 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. \ No newline at end of file +LOGIC: 2002 is not divisible by 4, therefore not a leap year.