From 72fc3c67ec4d4782bf95ab485e58c6a8f013cca2 Mon Sep 17 00:00:00 2001 From: aarush2410 <76821730+aarush2410@users.noreply.github.com> Date: Mon, 4 Oct 2021 18:09:11 +0530 Subject: [PATCH 1/3] sunny --- sunny.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 sunny.java diff --git a/sunny.java b/sunny.java new file mode 100644 index 0000000..815b1a2 --- /dev/null +++ b/sunny.java @@ -0,0 +1,36 @@ + import java.util.*; + public class SunnyNumberExample1 + { + //driver code + public static void main(String args[]) + { + Scanner sc = new Scanner(System.in); + System.out.print("Enter a number to check: "); + //reading a number from the user + int N=sc.nextInt(); + //calling user-defined function + isSunnyNumber(N); + } + //function checks whether the given is a perfect square or not + static boolean findPerfectSquare(double num) + { + //finds the square root of the ggiven number + double square_root = Math.sqrt(num); + //if square root is an integer + return((square_root - Math.floor(square_root)) == 0); + } + //function that checks whether the given number is Sunny or not + static void isSunnyNumber(int N) + { + //checks N+1 is perfect square or not + if (findPerfectSquare(N + 1)) + { + System.out.println("The given number is a sunny number."); + } + //executes if N+1 is not a perfect square + else + { + System.out.println("The given number is not a sunny number."); + } + } + } From 7e092492a1a34460aafd74bc920e618ea73665a8 Mon Sep 17 00:00:00 2001 From: aarush2410 <76821730+aarush2410@users.noreply.github.com> Date: Mon, 4 Oct 2021 18:11:00 +0530 Subject: [PATCH 2/3] evil --- evil.java | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 evil.java diff --git a/evil.java b/evil.java new file mode 100644 index 0000000..16bbf64 --- /dev/null +++ b/evil.java @@ -0,0 +1,73 @@ +import Java.util.*; +import java.io.*; +import java.util.Scanner; + +//create EvilNumberExample class to check whether the given number is an Evil number or not +public class EvilNumberExample { + + // create checkNumber() method that returns true when it founds number Evil + public static boolean checkNumber(int n) { + + // find the equivalence binary number using user defined convertToBinary() method + long binaryNumber = convertToBinary(n); + + // find total number of 1's in binary number + int count = 0; + + // iterate each digit of binary number + while(binaryNumber != 0) { + + // if the last digit of binary number is 1, increase the count value + if(binaryNumber % 10 == 1) + count++; + + // remove the last digit from the number + binaryNumber = binaryNumber / 10; + } + + // check whether the value of count is even or odd + if(count % 2 == 0) + return true; //return true when the value of count is even + + //return false if the value of the count is false + return false; + } + + //create convertToBinary() method to convert the decimal value into binary + private static long convertToBinary(int number) { + long binaryNumber = 0; + int rem = 0; + int j = 1; + while(number != 0) { + rem = number % 2; + binaryNumber += rem * j; + number = number / 2; + j = j * 10; + } + + return binaryNumber; //return the binary equivalent number of the decimal number + } + + //main() method start + public static void main(String[] args) { + + // declare variable in which the user entered value will be store + int num = 0; + + // create scanner class object + Scanner sc = new Scanner(System.in); + + //display custom message + System.out.print("Enter a number : "); + + //get input from user + num = sc.nextInt(); + + // check whether the number is evil number or not + if(checkNumber(num)) + System.out.println(num + " is an evil number"); + else + System.out.println(num + " is not an evil number"); + + } +} From 7513bb082df6ff03139c5d7f7c525f6c9fd0bf91 Mon Sep 17 00:00:00 2001 From: aarush2410 <76821730+aarush2410@users.noreply.github.com> Date: Mon, 4 Oct 2021 18:11:54 +0530 Subject: [PATCH 3/3] evil --- evil.java | 73 ------------------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 evil.java diff --git a/evil.java b/evil.java deleted file mode 100644 index 16bbf64..0000000 --- a/evil.java +++ /dev/null @@ -1,73 +0,0 @@ -import Java.util.*; -import java.io.*; -import java.util.Scanner; - -//create EvilNumberExample class to check whether the given number is an Evil number or not -public class EvilNumberExample { - - // create checkNumber() method that returns true when it founds number Evil - public static boolean checkNumber(int n) { - - // find the equivalence binary number using user defined convertToBinary() method - long binaryNumber = convertToBinary(n); - - // find total number of 1's in binary number - int count = 0; - - // iterate each digit of binary number - while(binaryNumber != 0) { - - // if the last digit of binary number is 1, increase the count value - if(binaryNumber % 10 == 1) - count++; - - // remove the last digit from the number - binaryNumber = binaryNumber / 10; - } - - // check whether the value of count is even or odd - if(count % 2 == 0) - return true; //return true when the value of count is even - - //return false if the value of the count is false - return false; - } - - //create convertToBinary() method to convert the decimal value into binary - private static long convertToBinary(int number) { - long binaryNumber = 0; - int rem = 0; - int j = 1; - while(number != 0) { - rem = number % 2; - binaryNumber += rem * j; - number = number / 2; - j = j * 10; - } - - return binaryNumber; //return the binary equivalent number of the decimal number - } - - //main() method start - public static void main(String[] args) { - - // declare variable in which the user entered value will be store - int num = 0; - - // create scanner class object - Scanner sc = new Scanner(System.in); - - //display custom message - System.out.print("Enter a number : "); - - //get input from user - num = sc.nextInt(); - - // check whether the number is evil number or not - if(checkNumber(num)) - System.out.println(num + " is an evil number"); - else - System.out.println(num + " is not an evil number"); - - } -}