Locating a 5 within a number

I’ve spent nearly a day attempting to create a program that can locate the digit 5 in a positive integer. If it does find a 5 in the remainder of the number, the program will display that a five was found; otherwise, it will display that no five was found. However, if there is a… Read More Locating a 5 within a number

Haskell modulo similar to JavaScript (takes sign into account and works for non-integers)

In JavaScript: console.log(13 % 5); // Expected output: 3 console.log(-13 % 5); // Expected output: -3 I need the same in Haskell. I did :{ modulo :: Double -> Int -> Double modulo a p = let p’ = fromIntegral p in if a > 0 then a – fromIntegral(p * floor(a/p’)) else a -… Read More Haskell modulo similar to JavaScript (takes sign into account and works for non-integers)

modulo gives wrong result for big number in Java

look at the below Java Code : long a = (long) 10e9+7; long b = (a * a); System.out.println("b is " + b); System.out.println("b%a is " + (b%a)); System.out.println(); BigInteger A = BigInteger.valueOf((long) 10e9+7); BigInteger B = A.multiply(A); System.out.println("B is " + b); System.out.println("B.mod(A) is " + B.mod(A)); Output: b is 7766279771452241969 b%a is 6015846137… Read More modulo gives wrong result for big number in Java

How to take a user input of 24 hour time in HHMM format? (without importing any modules)

I need to accept a user input for time, between 0000 and 2359, without importing any modules. I currently have it just taking an int input: fillTime = "X" while fillTime == "X": try: fillTime = int(input("Enter the time (0000-2359): ")) if fillTime < 0 or fillTime > 2359: print("Error! Please enter a valid time!")… Read More How to take a user input of 24 hour time in HHMM format? (without importing any modules)