Skip to main content

Featured

say hello world with C++ - Solution in Hacker Rank - hackerranksolutions8

  Objective This is a simple challenge to help you practice printing to  stdout . You may also want to complete  Solve Me First  in C++ before attempting this challenge. We’re starting out by printing the most famous computing phrase of all time! In the editor below, use either  printf  or  cout  to print the string  Hello ,World!  to  stdout . The more popular command form is  cout . It has the following basic form: cout<<value_to_print<<value_to_print; Any number of values can be printed using one command as shown. The  printf  command comes from C language. It accepts an optional format specification and a list of variables. Two examples for printing a string are: printf("%s", string);   printf(string); Note that neither method adds a newline. It only prints what you tell it to. Output Format Print   Hello ,World!   to stdout. Sample Output Hello, World! Solution:- //Say Hello, ...

Java Primality Test HackerRank Solution

 Problem:-

A prime number is a natural number greater than 1  whose only positive divisors are  1  and itself. For example, the first six prime numbers are 2,3 ,5 ,7 ,11 , and 13 .

Given a large integer,n , use the Java BigInteger class’ isProbablePrime method to determine and print whether it’s prime ornot prime.

Input Format

A single line containing an integer,  (the number to be checked).

Constraints

  •  n contains at most  100 digits.

Output Format

If n is a prime number, print prime; otherwise, print not prime.

Sample Input

13

Sample Output

prime

Explanation

The only positive divisors of 13 are 1 and 13 , so we print prime.

Solution:-

import java.io.*;


import java.math.*;


import java.security.*;


import java.text.*;


import java.util.*;


import java.util.concurrent.*;


import java.util.regex.*;



public class Solution {






   public static void main(String[] args) {


      Scanner in = new Scanner(System.in);


      BigInteger n = in.nextBigInteger();


      in.close();


      System.out.println(n.isProbablePrime(1) ? "prime" :"not prime");


    }


}

Comments