Write a java program that prints a series of prime numbers that end with 1.
Prompt the user for the first number (n1) and the last number(n2) in the series.
Print all possible prime numbers that ends with one from n1 to n2.
If n2 itself is prime, stop the series. Else print the nearest prime number that ends with one, next to n2
Answers
Answer:
dont know the answer man
Explanation:
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int cnt, i,j;
boolean flag=false;
System.out.print("Enter Starting Range : ");
int start = sc.nextInt();
System.out.print("Enter Ending Range : ");
int end = sc.nextInt();
System.out.println("List of Prime numbers are:");
for(i = start ; i <= end ; i++)
{
cnt = 0;
for(j = 1 ; j <= i ; j++)
{
if(i % j == 0)
cnt = cnt+1;
}
if(cnt == 2)
{
System.out.println(i);
flag = true;
}
}
if(flag == false)
System.out.println("No prime numbers found in the given range");
sc.close();
}
}
The above program first gets the range, then runs a for loop to check the list of prime numbers that exists in the range using modulus operator(%). "Flag" variable is used when there are no prime numbers found in the list.
To Know More:
1. https://brainly.in/question/9157879
Write a java program to calculate the time period of a Simple Pendulum by taking length and acceleration due to gravity as input
2. https://brainly.in/question/7463790
Write a program to find simple interest in java