Home Answers Viewqa Java-Beginners Prime Numbers from range

 
 


Dnyanesh Khedekar
Prime Numbers from range
2 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners

how to find prime numbers in a given range which are palindromes??

View Answers

December 21, 2010 at 5:12 PM


Hi Friend,

Try the following code:

import java.util.*;

public class PrimeAndPalindrome {
   static final int MAXNUMBER=200;
   private int number;
   private ArrayList<Integer> list = new ArrayList<Integer>();
   public PrimeAndPalindrome(int maxNum){
   number=maxNum;
   }
 ArrayList<Integer> isPalindrome(){
      for (int i=10; i<=number; i++){
         Integer in=new Integer(i);
         String number=in.toString();
         int index1=0;
         int index2=number.length()-1;
         char x=number.charAt(index1);
         char y=number.charAt(index2);
         while (index2-index1>=0){
         if(x!=y)
         break;
         if (index2-index1==0 || index2-index1==1)
         list.add(i);
         index1++;
         index2--;
         x=number.charAt(index1);
         y=number.charAt(index2);
         }
      }
      return list;
   }
   static boolean isPrime(int number){
      boolean isPrime=false;
      int i=(int) Math.ceil(Math.sqrt(number));
      while (i>1){
         if ((number!=i) && (number%i==0)){
            isPrime=false;
            break;
         }
         else if (!isPrime)
         isPrime=true;
         --i;
      }
      return isPrime;
   }
   public static void main(String[] args) {
      ArrayList<Integer> palindromes=new ArrayList<Integer>();
      PrimeAndPalindrome pp=new PrimeAndPalindrome(MAXNUMBER);
      palindromes=pp.isPalindrome();
      Iterator<Integer> iter=palindromes.iterator();
      while (iter.hasNext()){
         int current=iter.next();
         if (isPrime(current))
            System.out.println(current);
      }
   }
}

Thanks


December 23, 2010 at 10:49 AM


thnks buddy..but can u clearify what that ArrayList exactly doing?









Related Pages:
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 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 <
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.
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
Programming: Prime Numbers - Dialog
Java NotesProgramming: Prime Numbers - Dialog Name... 1 and themselves. For example, some of the first prime numbers are 2, 3, 5, 7, 11, 13, 17, ... Prime numbers have many interesting (at least
prime numbers - Java Beginners
prime numbers  Write a java program to find the prime numbers between n and m
Find Numbers which are palindrome and prime
Find Numbers which are palindrome and prime In this section, you will learn how to find the numbers from 1 to 500 which are palindrome and prime. To compute...() of boolean type. Now the list contains all the numbers which are palindrome
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 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
write an application that print out the even numbers between the range 100-200
write an application that print out the even numbers between the range 100-200   write an application that print out the even numbers between the range 100-200 ?   The given code accepts the number from 100 to 200
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 Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any... automatically prints Prime Number starting from 1 to 50. Example of Prime Number... + " "); } } } Output: Prime Number from 1 to 50 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43
prime number question - Java Beginners
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 question  For the question located here: http
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
numbers
numbers  Write a program that read 15 integers between 0 and 6 and a method to search, displays and returns the number that has the highest occurrence. Prompt the user if the number is not within this range.   Hello
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 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
Mysql Time Range
, but helps you to assign values to Time columns using either strings numbers. Understand with Example The Tutorial illustrate an example from 'Mysql Time Range... Mysql Time Range      
print the even numbers between the range 100-200
print the even numbers between the range 100-200  Q ?write an application that print out the even numbers between the range 100-200 ? 1- which aer... prints out the even numbers between the range of 100 and 200 and then determine
Program to display palindrome numbers between some range
Program to display palindrome numbers between some range  Hi!I want a java program to display palindrome numbers between 100 to 1000.can you please explain me the logic with an example   import java.util.*; public
Java find prime numbers without using break statement
Java find prime numbers without using break statement In this tutorial, you will learn how to find the prime numbers without using break statement. You all are aware of Prime Numbers, these are the numbers which are either divided
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
date range in sql
date range in sql  How can I select a random date from a date range in SQL server
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.
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
range of dates in mysql query
range of dates in mysql query  How to select the range of dates in mysql ..when i have to select from between & and of date function?   SELECT * FROM MAAccounts WHERE updatedOn BETWEEN ? AND ? ORDER
Prime And Fibonacci Number Finder
Prime And Fibonacci Number Finder In this section, you will learn how to find the prime numbers which are generated in the fibonacci series. To compute... numbers in the list. The Iterator class iterates the ArrayList and check whether
Numbers
Java NotesNumbers Two kinds of numbers. There are basically two kinds of numbers in Java and most other programming languages: binary integers (most commonly using the type int) and binary floating-point numbers (most commonly using
MySQL range
in the particular range of values but there is not any predefined function in MySQL but we can also find that particular range's data from the database in MySQL using... MySQL range       May
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
PRIME AND EVEN AND ODD - Java Interview Questions
PRIME AND EVEN AND ODD  how to write prime numbers?i want source code? how to write even numbers? i want source code? how to write odd numbers ?i... args[]){ String primeNo = ""; int j=0; System.out.println("Prime Numbers
Random numbers - Introduction
. Type, Range, and Distribution When you generate random numbers, you need to decide... numbers in the range are equally likely to be produced. How can a computer... Java NotesRandom numbers - Introduction When to use random numbers
Prime Number in Java
Prime Number in Java       This Java programming tutorial, we will be read how to get prime number... in this program we use two 'for' loop. For loop will start from 1 to entered number
read a positive real numbers from highest to lowest
read a positive real numbers from highest to lowest  write a java program that will read a sequence of 10 positive real nos. entered by the user and will print the same numbers in sorted order from lowest to highest using arrays
Random numbers - Development process
Random numbers  hi, How to generate unique random numbers between range like(10 to 50)  Hi friend, class RandomNumber { public static void main(String[] args) { //set the variable aNumber
recursion numbers - Java Beginners
recursion numbers  I need to use recursion to test all values from 0 to 20 and see if they are contain in a 1-D array with values: 2,4,6,8,10,12,14,16,18,20. The results of all numbers from 0-20 will be printed
Sum of first n numbers
; } System.out.println("Sum of Numbers from 1 to "+n+" : "+sum...Sum of first n numbers  i want a simple java program which will show the sum of first n numbers....   import java.util.*; public class
Applet for add two numbers
numbers?   import java.awt.Graphics; import javax.swing.*; public...() { String num1; String num2; // read first number from the keyboard... number from the ketboard num2 = JOptionPane.showInputDialog("Enter a Second
permutstion of numbers in java
permutstion of numbers in java  Is it possible to enter the number in a char so that permutation of a number can be acheived which... initialized the char as(1,2,3).but its not working when i want the input from user
Generate array of random numbers
. In this section, we are going to accept 10 numbers and display 5 numbers from them...Generate array of random numbers You can generate a random number either...() but it is better to use Random class. If you want to generate a series of random numbers
prime number
prime number  To check a number entered by user is prime
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
numbers - Java Beginners
numbers  Write a program to create a file named "numbers.dat". Then create an algorithm that adds all even numbered integers from 1 to 100, separated... the odd number integers from 1 to 100, separated by a comma to the end of the file
simple javascript validation for numbers
simple javascript validation for numbers  simple javascript validation for register number   Here is a html code that accepts number from the user and check whether the entered value is valid. <html> <head>
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
How do I change the while loop in this code to the range with range list style display page for a resultSet() in jsp?
How do I change the while loop in this code to the range with range list style...; <title>Count data from database in jsp</title> </head> <...;Count data from database in jsp</font></h2> <form method="POST" >
About Dr. Karni Singh Shooting Range Delhi
The Dr. Karni Singh Shooting Range in Delhi Most people who travel to Delhi may not think that a shooting range is a worthwhile attraction. However, there is a very special shooting range in Delhi. This is the Dr. Karni Singh Shooting
Random numbers - API
directly useful numbers from the Random class. java.util.Random class To use... The Math.random() method returns random double numbers in the range >=0.0... Java NotesRandom numbers - API Two classes. Java provides the Math.random
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.