From 53194055d7083820942da7cf49c986d5ef345ee9 Mon Sep 17 00:00:00 2001 From: AbhijithRam Date: Mon, 17 Oct 2022 20:33:57 +0530 Subject: [PATCH 1/2] Adding krishnamurthy number --- krishnamurthyno.java | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 krishnamurthyno.java diff --git a/krishnamurthyno.java b/krishnamurthyno.java new file mode 100644 index 0000000..7af8a58 --- /dev/null +++ b/krishnamurthyno.java @@ -0,0 +1,62 @@ +//import required classes and packages +import Java.util.*; +import java.io.*; +import java.util.Scanner; + +//create KrishnamurthyNumber class to check whether the given number is a Krishnamurthy number or not +class KrishnamurthyNumber { + + // create fact() method to calculate the factorial of the number + static int fact(int number) + { + int f = 1; + while (number != 0) { + f = f * number; + number--; + } + return f; + } + + // create checkNumber() method that returns true when it founds number krishnamurthy + static boolean checkNumber(int number) + { + int sum = 0; //initialize sum to 0 + + int tempNumber = number; //create a copy of the original number + + //perform operation until tempNumber will not equal to 0 + while (tempNumber != 0) { + // calculate the factorial of the last digit of the tempNumber and then add it to the sum + sum = sum + fact(tempNumber % 10); + + // replace the value of tempNumber by tempNumber/10 + tempNumber = tempNumber / 10; + } + + // Check whether the number is equal to the sum or not. If both are equal, number is krishnamurthy number + if(sum == number) + return true; + else + return false; + } + + // main() method start + public static void main(String[] args) + { + int n; //initialize variable n + + //create scanner class object to read data from user + Scanner sc = new Scanner(System.in); + + //custom message + System.out.println("Enter any number:"); + + //store user entered value into variable n + n = sc.nextInt(); + + if (checkNumber(n)) + System.out.println(n + " is a krishnamurthy number"); + else + System.out.println(n + "is not a krishnamurthy number"); + } +} \ No newline at end of file From c87504aa71dff122bebdfd47437244579ef33594 Mon Sep 17 00:00:00 2001 From: ABHIJITH RAM P Date: Sun, 23 Oct 2022 22:33:12 +0530 Subject: [PATCH 2/2] adding timer program --- timer.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 timer.py diff --git a/timer.py b/timer.py new file mode 100644 index 0000000..7fcf2c7 --- /dev/null +++ b/timer.py @@ -0,0 +1,13 @@ +import time + +def countdown(time_sec): + while time_sec: + mins, secs = divmod(time_sec, 60) + timeformat = '{:02d}:{:02d}'.format(mins, secs) + print(timeformat, end='\r') + time.sleep(1) + time_sec -= 1 + + print("stop") + +countdown(5)