Sunday, January 27, 2019

a. prime or not
Prime number: A prime number is a whole number greater than 1 whose only factors are 1 and itself.
Ans:
---
public class PrimeTest {
public static void main(String[] args) {
int n, i, k=0;
            System.out.println("Enter a positive integer: ");
            Scanner sc = new Scanner(System.in);
            n=sc.nextInt();
            for(i=2;i<=n/2;++i){
                 if(n%i==0){
                       k=1;
                       break;
                 }
             }
             if (k==0)
                  System.out.println(n+" is a prime number");
             else {
                 System.out.println(n+" is not a prime number");
              }
              sc.close();
}
}
Output:
-------
Enter a positive integer: 29
29 is a prime number.

Related Posts:

  • How to iterate through a Map Elements we cannot iterate a Map directly using iterators, because Map are not Collection. There are different methods to iterate through MAP elements: Method 1: Using Iterator and keySet(). package seleniumrepo; import java.ut… Read More
  • Armstrong Program in Java Write a Java program to find whether given number is Armstrong or not Armstrong numbers are: 153, 370, 371, 407 Definition: We call a given number as Armstrong if it is equal to the sum of the powers of its own digits. Ex:&n… Read More
  • BufferedReader vs Scanner Difference between BufferedReader and Scanner: It can parse the user input and read an int, short, byte, float, long and double apart from String. On the other hand, BufferedReader can only read String in Java. BuffredReade… Read More
  • White Box Testing (WBT) vs Black Box Testing (BBT) Difference between White Box Testing and Black Box Testing: WBT: This is defined as method of testing in which one can perform testing on an application having internal structural knowledge of it. This is also kno… Read More
  • Arraylist vs HashMap Difference between Arraylist and HashMap? ArrayList implements List Interface while HashMap is an implementation of Map interface. Memory consumption is high in HashMap compared to the ArrayList. ArrayList maintains the ins… Read More

0 comments:

Post a Comment

Selenium Training in Realtime

Blog helps to a student or IT employee to develop or improve skills in Software Testing.

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts