Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Anamika Shukla
prime nos
1 Answer(s)      3 years ago
Posted in : Java Beginners


Instead of using break statement in finding the prime nos ,is there any other way ?? if it is there pls tell that also


Advertisement
View Answers

January 10, 2012 at 3:29 PM


import java.io.*;
class FindPrimeWithoutBreak
{
    public static void main(String[] args) {
      for (int number = 2; number <= 100; number++) {
         int maxFactor = (int)Math.sqrt(number);
         boolean isPrime = true;
         int factor = 2;
         while (isPrime && factor <= maxFactor) {
            if (number % factor == 0) { 
                isPrime = false;
            }
            factor++;
         }
         if (isPrime) System.out.println(number);
      }
   }
}


Related Tutorials/Questions & Answers:
prime nos
prime nos  Instead of using break statement in finding the prime nos ,is there any other way ?? if it is there pls tell that also   import java.io.*; class FindPrimeWithoutBreak { public static void main(String
counting the positive,negative and zero nos. - Java Beginners
counting the positive,negative and zero nos.  Create a program that will input n number, and determine the number of positive, negative
Advertisements
prime number
prime number  To check a number entered by user is prime
prime number
prime number  write a java program for prime number
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
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 palindrome
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 palendrome
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
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 number
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
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
prime number  to check wethere given number is prime or not?  ... is Prime!"); } else{ System.out.println("Number is not prime!"); } } } Thanks
Prime Numbers
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
Palindromic Prime Numbers
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
prime numbers - Java Beginners
prime numbers  Write a java program to find the prime numbers between n and m
finding the prime numbers
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... number is prime or not, follow the link and it will provide you in depth knowledge
prime number - Java Beginners
prime number  this project is to determine if a phone number is a prime number. if the number is a prime number then print a message to the effect. if the number is not a prime number then print the prime factors of the number
Prime Numbers - IDE Questions
Prime Numbers  Create a program that calculates the prime numbers from any inputted start and end range of values (e.g. 5 and 28) and print the prime... = 0; System.out.println("Prime Numbers are:" ); for (int i = 1; i <
prime number - Java Beginners
prime number  i want to write a code in java that picks prime numbers... non prime numbers when prime numbers are finished   Hi Friend, Try...); System.out.println("Prime Numbers are: "); for(int i=0;i
prime numbers application
prime numbers application  how to add a comment indicating that the method will determine if a number is a prime number. In the next line add... a comment stating that 1 is not a valid prime number, on the next line add
Find prime factors of non prime number
Find prime factors of non prime number In this section, you will learn how to find the prime factors of the non prime number. Here we have prompted the user to enter any number. If the number entered by the user is prime then we have
prime pal - Java Beginners
prime pal  1) WAP to print all prime-palindrome number range between 1-500 2) WAP to print all prime-Fibonacci number range between 1-500   Hi Friend, 1)Prime and Palindrome: import java.util.
Prime Numbers from range
Prime Numbers from range  how to find prime numbers in a given range which are palindromes??   Hi Friend, Try the following code: import java.util.*; public class PrimeAndPalindrome { static final int MAXNUMBER
prime number question - Java Beginners
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
Prime Number program in Java
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
Prime Number in Java
Prime Number in Java       This Java programming tutorial will be read how to get prime number. First of all we will define a class "Prime Number". Java I/O package
Find out the prime number
Find out the prime number      ... to find out whether a given number is prime or not. Here we have used the 'for loop' statement and given the required condition for a prime number. As we know
Finding all palindrome prime numbers - Java Beginners
Finding all palindrome prime numbers  How do i write a program to Find all palindrome prime numbers between two integers supplied as input (start and end points are excluded
Pick Prime Numbers from the ArrayList
Pick Prime Numbers from the ArrayList Programmers mostly used ArrayList... integer values in the arraylist and from the arraylist we have to find the prime and non prime numbers separately. Here is the code: import java.util.
Advertisements
 

 

 

DMCA.com