prime number program in java
Java
public class Prime {
public static void main(String[] args) {
int num = 29;
boolean flag = false;
for(int i = 2; i <= num/2; ++i){
if(num % i == 0){
flag = true;
break;
}
}
if (!flag)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}}public class Prime {
public static void main(String[] args) {
int num = 29;
boolean flag = false;
for(int i = 2; i <= num/2; ++i)
{
// condition for nonprime number
if(num % i == 0)
{
flag = true;
break;
}
}
if (!flag)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}
}
Also in Java:
- Title
- java divisible by operator
- Category
- Java
- Title
- how to read in a file in java
- Category
- Java
- Title
- java string reverse
- Category
- Java
- Title
- random code
- Category
- Java
- Title
- replace regex group() java
- Category
- Java
- Title
- multiple string java
- Category
- Java
- Title
- determine if a given binary tree is a valid bst
- Category
- Java
- Title
- java read file text
- Category
- Java
- Title
- set iteration java
- Category
- Java
- Title
- double to string java
- Category
- Java
- Title
- Write a JAVA method that expands a given binomial (ax + by)n, where integers a, b, n are user inputs. For example, if a = 2, b = -12, n = 4 are entered the method should print or return
- Category
- Java
- Title
- java output length of each line in a text document
- Category
- Java
- Title
- java remove non numbers from string
- Category
- Java
- Title
- java get annotation value
- Category
- Java
- Title
- multiplication program java
- Category
- Java
- Title
- java program to display characters from a to z using loop
- Category
- Java
- Title
- pass list to intent in android java
- Category
- Java
- Title
- how to do for each in java
- Category
- Java
- Title
- java flood fill
- Category
- Java
- Title
- java calculator code
- Category
- Java
- Title
- getindexrequest elasticsearch
- Category
- Java
- Title
- java 8 find min value in array
- Category
- Java
- Title
- java scanner input int
- Category
- Java
- Title
- java hashmap get value
- Category
- Java
- Title
- how to import a scanner in java
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- how to exit a for loop in java
- Category
- Java
- Title
- java 8 validate based on pair of strings
- Category
- Java
- Title
- int java
- Category
- Java
- Title
- iterate through hashmap in java
- Category
- Java
- Title
- applicationcontext.xml
- Category
- Java
- Title
- java making a screen
- Category
- Java
- Title
- java lerp
- Category
- Java
- Title
- big integer java
- Category
- Java
- Title
- nth prime number java
- Category
- Java
- Title
- how to define an arraylist in java
- Category
- Java
- Title
- arraylist to array java
- Category
- Java
- Title
- android how to know when snackbar is done
- Category
- Java
- Title
- is self divisor java
- Category
- Java
- Title
- array rotation program in java
- Category
- Java
- Title
- java newinstance alternative
- Category
- Java
- Title
- how to loop through an array
- Category
- Java
- Title
- read a mail and its content in java mail api
- Category
- Java
- Title
- string remove last character
- Category
- Java
- Title
- indexof java
- Category
- Java
- Title
- what is a float java
- Category
- Java
- Title
- in dom parser how to find processing instruction in java
- Category
- Java
- Title
- boolean checkbox swing
- Category
- Java
- Title
- j
- Category
- Java
- Title
- get current day java
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- how to check if a string is in alphabetical order in java
- Category
- Java
- Title
- java get folder content
- Category
- Java
- Title
- log4j print stacktrace
- Category
- Java
- Title
- java remove first character from string
- Category
- Java
- Title
- validate isbn number java
- Category
- Java
- Title
- how to add element to arraylist
- Category
- Java
- Title
- ujava saum of positive integers
- Category
- Java
- Title
- spigot custom mob
- Category
- Java
- Title
- print in one line in java
- Category
- Java
- Title
- cannot fit requested classes in a single dex file
- Category
- Java
- Title
- méthode retourne nom classe java
- Category
- Java
- Title
- trees in java
- Category
- Java
- Title
- displaying an arraylist in java
- Category
- Java
- Title
- java how to print a newline
- Category
- Java
- Title
- connect 2 package in android
- Category
- Java
- Title
- how to echo java_home in windows cmd
- Category
- Java
- Title
- java get current milliseconds
- Category
- Java
- Title
- android how to switch between activities
- Category
- Java
- Title
- dicom read with java
- Category
- Java
- Title
- how to check wether the property exist in a object in java script
- Category
- Java
- Title
- string length in java
- Category
- Java
- Title
- computeifabsent hashmap java
- Category
- Java
- Title
- executors java
- Category
- Java
- Title
- map with insertion order preserved java
- Category
- Java
- Title
- java array
- Category
- Java
- Title
- how to get length of integer in java
- Category
- Java
- Title
- override java
- Category
- Java
- Title
- find the day of the week Calendar class in java
- Category
- Java
- Title
- java test if a string is a int
- Category
- Java
- Title
- how to separate no and text in java
- Category
- Java
- Title
- how to copy list item to another list in java
- Category
- Java
- Title
- how to select a element in an arraylist java
- Category
- Java
- Title
- taking string input in java
- Category
- Java
- Title
- Java nested array hashcode
- Category
- Java
- Title
- spigot run task later
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- java define custom exception
- Category
- Java
- Title
- editer un label java
- Category
- Java
- Title
- are strings modifiable
- Category
- Java
- Title
- java hashmap put
- Category
- Java
- Title
- update value of an arraylist java
- Category
- Java
- Title
- get day name from date in java
- Category
- Java
- Title
- how to get binary value in java
- Category
- Java
- Title
- File Parser java
- Category
- Java
- Title
- int to binary string java
- Category
- Java
- Title
- java generic calling clone method
- Category
- Java
- Title
- check java version
- Category
- Java
- Title
- parseints(str) java
- Category
- Java
- Title
- java check if string is number
- Category
- Java