nth prime number java
Java
import java.util.Scanner;
public class NthPrime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter n to compute the nth prime number: ");
int nth = sc.nextInt();
int num, count, i;
num=1;
count=0;
while (count < nth){
num=num+1;
for (i = 2; i <= num; i++){ //Here we will loop from 2 to num
if (num % i == 0) {
break;
}
}
if ( i == num){//if it is a prime number
count = count+1;
}
}
System.out.println("Value of nth prime: " + num);
}
}
Also in Java:
- Title
- java convert string with commas to long
- Category
- Java
- Title
- how to create a Rectangle in java
- Category
- Java
- Title
- android studio centering textview in relativelayout
- Category
- Java
- Title
- bigdecimal divide java
- Category
- Java
- Title
- how to add a keylistener to a jframe
- Category
- Java
- Title
- cannot fit requested classes in a single dex file
- Category
- Java
- Title
- how to parse a string into a number in java
- Category
- Java
- Title
- same method name with different arguments
- Category
- Java
- Title
- java setter
- Category
- Java
- Title
- java array declaration
- Category
- Java
- Title
- java generate list of random element
- Category
- Java
- Title
- java output length of each line in a text document
- Category
- Java
- Title
- java replace all html tags
- Category
- Java
- Title
- how to get all of the chldren of a panel in java
- Category
- Java
- Title
- how to pass parameters to xsl file
- Category
- Java
- Title
- java nextpermutation
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- how to print an array in java
- Category
- Java
- Title
- java read integer from text file into array scanner
- Category
- Java
- Title
- runtime java examples
- Category
- Java
- Title
- java print type of object
- Category
- Java
- Title
- if statement java
- Category
- Java
- Title
- java get environment variables
- Category
- Java
- Title
- demo java file
- Category
- Java
- Title
- searching in database using java
- Category
- Java
- Title
- how to create an action listener in java
- Category
- Java
- Title
- java script how to not allow soace
- Category
- Java
- Title
- how to calculate exponential in java
- Category
- Java
- Title
- creating array java
- Category
- Java
- Title
- java map example
- Category
- Java
- Title
- how to reverse a list in java
- Category
- Java
- Title
- java animated gif example
- Category
- Java
- Title
- get sha key android
- Category
- Java
- Title
- java double 2 decimal
- Category
- Java
- Title
- java define custom exception
- Category
- Java
- Title
- null pointer exception java
- Category
- Java
- Title
- round no in java
- Category
- Java
- Title
- how to fill a list with a single value java
- Category
- Java
- Title
- primitive data types in java
- Category
- Java
- Title
- how to add a number to an array in java
- Category
- Java
- Title
- java read from file
- Category
- Java
- Title
- sdkmanager JAVA_HOME invalid directory
- Category
- Java
- Title
- arraylist add method
- Category
- Java
- Title
- how to run java program in linux server
- Category
- Java
- Title
- java call another constructor
- Category
- Java
- Title
- create jdbc connection in java
- Category
- Java
- Title
- how to check if a string contains only alphabets and space in java
- Category
- Java
- Title
- how to skip a line in java
- Category
- Java
- Title
- how to print a 2d array in java
- Category
- Java
- Title
- isSelfDivisor java
- Category
- Java
- Title
- usaco 2018 january contest
- Category
- Java
- Title
- ecommerce app github android
- Category
- Java
- Title
- how to compare strings java
- Category
- Java
- Title
- java lerp
- Category
- Java
- Title
- remove extra blank spaces from string in java
- Category
- Java
- Title
- jar file not running after being compiled
- Category
- Java
- Title
- 2d array java
- Category
- Java
- Title
- retrofit
- Category
- Java
- Title
- java run project from command line
- Category
- Java
- Title
- spigot actionbar
- Category
- Java
- Title
- java command line arguments
- Category
- Java
- Title
- how to crate a list in java script
- Category
- Java
- Title
- how to use beacon power in minecraft in java edition
- Category
- Java
- Title
- java scanner next()
- Category
- Java
- Title
- generate random number java
- Category
- Java
- Title
- java check if file exists
- Category
- Java
- Title
- How to draw Bezier Curve in Android
- Category
- Java
- Title
- java file download
- Category
- Java
- Title
- how to do 4th root java
- Category
- Java
- Title
- how to set a windows background image tkinter
- Category
- Java
- Title
- map.keyset in java
- Category
- Java
- Title
- loop and save letters in a string java
- Category
- Java
- Title
- set password visible in android
- Category
- Java
- Title
- read a file in java and store as integer array using buffered reader
- Category
- Java
- Title
- Error executing Maven. java.io.FileNotFoundException: The specified user settings file does not exist: /etc/java-8-openjdk
- Category
- Java
- Title
- java making a screen
- Category
- Java
- Title
- java convert char to int
- Category
- Java
- Title
- joptionpane.showconfirmdialog yes no example
- Category
- Java
- Title
- list java replace
- Category
- Java
- Title
- write file java
- Category
- Java
- Title
- java remove first character from string
- Category
- Java
- Title
- declareing a variable in java
- Category
- Java
- Title
- java http client eviction
- Category
- Java
- Title
- java concatenate arrays
- Category
- Java
- Title
- separateur JMenu swing java
- Category
- Java
- Title
- how to minimize jframe in java
- Category
- Java
- Title
- android create snackbar
- Category
- Java
- Title
- java script to detect the crome browser
- Category
- Java
- Title
- 3-way radix quicksort java
- Category
- Java
- Title
- java arraylist to array
- Category
- Java
- Title
- FileNotFoundException: properties/fortunes.txt (No such file or directory)
- Category
- Java
- Title
- java int to int array
- Category
- Java
- Title
- system.in example in java
- Category
- Java
- Title
- The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the `--no-shrink` flag to this command.
- Category
- Java
- Title
- applicationcontext.xml
- Category
- Java
- Title
- spigot sounds
- Category
- Java
- Title
- convert array of int to arraylist java
- Category
- Java
- Title
- how to bubblesort a string array in java
- Category
- Java
- Title
- stackoverflow java enum with constructor
- Category
- Java
- Title
- java replace all xml decoding
- Category
- Java