View Answers

June 29, 2009 at 10:28 AM

Hi Friend,

Try the following code:

import java.util.*;

class PrimeNumbers{

public static void main (String args[]){

System.out.println("Enter the start range:");

Scanner input=new Scanner(System.in);

int num1=input.nextInt();

System.out.println("Enter the end range:");

int num2=input.nextInt();

String primeNo = "";

int counter = 0;

System.out.println("Prime Numbers between "+num1+" and "+num2+" are:" );

for (int i = 5; i < 20; i++){ {

int j;

for (j = 2; j < i; j++)

{

if (i % j == 0) {

break;

}

}

if (i == j) {

primeNo += i + " ";

}

}

}

System.out.println(primeNo);

}

}

Thanks

Try the following code:

import java.util.*;

class PrimeNumbers{

public static void main (String args[]){

System.out.println("Enter the start range:");

Scanner input=new Scanner(System.in);

int num1=input.nextInt();

System.out.println("Enter the end range:");

int num2=input.nextInt();

String primeNo = "";

int counter = 0;

System.out.println("Prime Numbers between "+num1+" and "+num2+" are:" );

for (int i = 5; i < 20; i++){ {

int j;

for (j = 2; j < i; j++)

{

if (i % j == 0) {

break;

}

}

if (i == j) {

primeNo += i + " ";

}

}

}

System.out.println(primeNo);

}

}

Thanks

Ads

Related Tutorials/Questions & Answers:

prime number question For the question located here: http... has to input the two numbers and it displays the prime numbers within the range...; System.out.println("Prime Numbers between "+num1+" and "+num2

Advertisements

prime number get one number and check the number prime or not using if statement Java Check Prime Number

prime number HI!I want a java program that accepts a number from user and displays whether it is a prime number or not using BufferedReader

prime number To check a number entered by user is prime or not? Java check prime number import java.util.*; class CheckPrimeNumber... is Prime!"); } else{ System.out.println("Number

prime number could u pls help me out in finding whether a number is a prime number or not? import java.util.*; class CheckPrimeNumber... is Prime!"); } else{ System.out.println("Number

prime number to check wethere given number is prime or not? ... is Prime!"); } else{ System.out.println("Number... { static boolean isPrime(int number){ boolean isPrime=false; int

ModuleNotFoundError: No module named 'Is_this_a_prime_number' Hi...: No module named 'Is_this_a_prime_number' How to remove the ModuleNotFoundError: No module named 'Is_this_a_prime_number' error? Thanks Hi

Prime Number program in Java will print the prime numbers between 1 to any given number. Prime Number is a number that is not divisible by any number other... automatically prints Prime Number starting from 1 to 50. Example of Prime Number

ModuleNotFoundError: No module named 'get-prime-number' Hi, My... named 'get-prime-number' How to remove the ModuleNotFoundError: No module named 'get-prime-number' error? Thanks Hi, In your

ModuleNotFoundError: No module named 'prime_number_checker' Hi...: No module named 'prime_number_checker' How to remove the ModuleNotFoundError: No module named 'prime_number_checker' error? Thanks Hi

Prime number program in java In this example you will learn how to write... a class with class name prime number, using switch case, in case first using two for loop generating prime number up to the limit number entered by user

Prime Number in Java In this Java tutorial , you will learn how to write a Java program to get prime numbers between 1 to the desired number. To start..., if the number is divisible by any number, it means it is not prime otherwise

I have posted a number of question but no one has answered? No one has responded for ten days now. However my first question was answered on the same day. Is there a limit to the number of questions you can ask or am I doing

prime palindrome Hi I want to write a program in pascal that ask a user to input a number, the program then list all the prime number that are palindrome below the number entered. thks

prime palendrome Hi I want to write a program that ask a user to input a number, the program then list all the prime number that are palindrome below the number entered. Thks

prime palindrome Hi I want to write a program that ask a user to input a number, the program then list all the prime numbers that are palindrome below the number entered. In pascal language Thanks

prime nos Instead of using break statement in finding the prime nos...[] args) { for (int number = 2; number <= 100; number++) { int maxFactor = (int)Math.sqrt(number); boolean isPrime = true; int

Palindromic Prime Numbers Write a program that finds the first palindromic prime number above 100,000. Include the value of this prime in a comment at the start of the code

number is prime or not, follow the link and it will provide you in depth knowledge...finding the prime numbers Hi, I am a beginner to java and I have problem with the code in finding the prime numbers, can someone tell me about

question sir plz tell me what should i give in title box. just i want java program for the question typed in this area

question sir plz tell me what should i give in title box. just i want java program for the question typed in this area

Prime Numbers Create a complete Java program that allows the user to enter a positive integer n, and which then creates and populates an int array with the first n prime numbers. Your program should then display the contents

question dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word

question Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory