# Write a program to find nth prime number using Java?

3,127 views
Write a program to find nth prime number using Java?
posted Apr 22, 2017

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++){
if (num % i == 0) {
break;
}
}
if ( i == num){
count = count+1;
}
}
System.out.println("Value of nth prime: " + num); } }

Let me execute this problem
i need this c language
Similar Questions

Rohit wants to add the last digits of two given numbers.
For example, If the given numbers are 267 and 154, the output should be 11.

Below is the explanation -
Last digit of the 267 is 7
Last digit of the 154 is 4
Sum of 7 and 4 = 11

### Write a program to help Rohit achieve this for any given two numbers.

Note: The sign of the input numbers should be ignored. i.e.
if the input numbers are 267 and 154, the sum of last two digits should be 11
if the input numbers are 267 and -154, the sum of last two digits should be 11
if the input numbers are -267 and 154, the sum of last two digits should be 11
if the input numbers are -267 and -154, the sum of last two digits should be 11

Example :
Let the list be {2,3,5} and Assume always 1 be included then

2th number is 2
3th number is 3
4th number is 4
5th number is 5
6th number is 6
7th number is 8
8th number is 9
9th number is 10
10th number is 12
11th number is 15 and so on...