Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,420 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,359 people online right now. Registration is fast and FREE... Join Now!




testing integers to determine palindromes

 
Reply to this topicStart new topic

testing integers to determine palindromes, Topic merged

jdozier
14 Oct, 2008 - 01:37 PM
Post #1

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 4

i am having difficulty with the following:
1) input a beginning number
2) add its reverse
3) continue the process until it becomes a palindrome
4) count the number of iterations that it takes for the beginning number to become a palindrome and output the result


CODE
import java.util.*;

class PROG3
{
  
  public static void main(String[]args)
{
  Scanner input = new Scanner(System.in);
  Scanner number = input.nextInt(); //error states incompatible types
  System.out.println("Please enter a positive number to test");
  
  
  String number = " ";  //error states number already defined in main(java.lang.String[])
  String reversed = " ";
  int j = 0; //counts the number of iterations
  
  int n = Integer.parseInt(number); //error states cannot find symbol method parseInt(java.util.Scanner)
  int r = Integer.parseInt(reversed);
  int sum = n+r;
  String x = " ";
  int x = x.valueOf(sum);
  
  
  for(int i = number.length-1; i>=0; i--) //error states cannot find variable length
  reversed = reversed + number.substring(i,i+1); //error states cannot find symbol method substring(int,int)
  j = j+1;

  
  
  
  if(isPalindrome(x)) //error states cannot find symbol method isPalindrome(java.lang.String)
  {
  System.out.println(x + "_" + "is a palindrome" + "_" + "with" + "_"
                         + j + "_" + "number of iterations");
  }
  else
  {
    return false; //error states cannot return a value from method whose result type is void
  }
  
    
}
}

  


User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Testing Integers To Determine Palindromes
14 Oct, 2008 - 01:49 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 3,993



Thanked: 16 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
please do not post duplicate posts.
User is online!Profile CardPM
+Quote Post

jdozier
RE: Testing Integers To Determine Palindromes
14 Oct, 2008 - 01:55 PM
Post #3

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 4

i am trying to write a program finding palindromes and currently having difficulty achieving the following:

1) input a beginning number
2) add the reverse of that number
3) continue the process until it becomes a palindrome
4) determine the number of iterations necessary for the number to become a palindrome and output the results.

here's what i have so far. thank you in advance

CODE
import java.util.*;

class PROG3
{
  
  public static void main(String[]args)
{
  Scanner input = new Scanner(System.in);
  Scanner number = input.nextInt(); //error states incompatible types
  System.out.println("Please enter a positive number to test");
  
  
  String number = " ";  //error states number already defined in main(java.lang.String[])
  String reversed = " ";
  int j = 0; //counts the number of iterations
  
  int n = Integer.parseInt(number); //error states cannot find symbol method parseInt(java.util.Scanner)
  int r = Integer.parseInt(reversed);
  int sum = n+r;
  String x = " ";
  int x = x.valueOf(sum);
  
  
  for(int i = number.length-1; i>=0; i--) //error states cannot find variable length
  reversed = reversed + number.substring(i,i+1); //error states cannot find symbol method substring(int,int)
  j = j+1;

  

User is offlineProfile CardPM
+Quote Post

jdozier
RE: Testing Integers To Determine Palindromes
14 Oct, 2008 - 02:18 PM
Post #4

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 4

sorry, it didn't appear that the first one actually posted so i tried again.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 01:05PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month