Prime Time Problem Coderbyte Solution

0

Have the function PrimeTime(num) take the num parameter being passed and return the string true if the parameter is a prime number, otherwise return the string false. The range will be between 1 and 2^16.

Here is prime time problem solution,

Prime time program in java


import java.util.Scanner;


public class PrimeTime {
boolean PrimeTime(long num) {
if (num %2 == 0) return false;

for (int i = 3; i * i <= num; i += 2) {
if (num % i == 0)
return false;
}
return true;
}

public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
PrimeTime c = new PrimeTime();
System.out.print(c.PrimeTime(123456));
}
}

Prime time program in python


def PrimeTime(num):
i = 2
while i < num:
if num%i == 0:
return 'false'
else:
i += 1
return 'true'


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !