August 17, 2018

To check whether a number is prime in java algorithm

/**
 * To check whether a number is prime in java algorithm
 */
package com.belazy.tricks;

import java.math.BigInteger;

/**
 * @author itsection kozhikode
 *
 */
public class Consumerfed {

/**
* @param args
*/
public static void main(String[] args) {
//multiplying by 2
int i = 10;
i= i << 1;
System.out.println(i);

//swapping 2 numbers
int a = 20;
int b = 30;
b^=a;
a^=b;
b^=a;
System.out.println("a="+a +": b="+b);

//counting the digits
double n =10000000;
double N = Math.floor(Math.log10(n )) + 1;
System.out.println("number's count : "+N);

//checking prime number
int p = 17;
System.out.print("checking prime number :");
System.out.println(BigInteger.valueOf(p).isProbablePrime(1));

System.out.println("-- Jerin V George");


}

}

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments