J'essaie d'écrire un programme qui convertit un long en une chaîne et vérifie s'il s'agit d'un palindrome, j'ai écrit ce qui suit jusqu'à présent, mais cela me donne une erreur de type incompatible, et je n'arrive pas à trouver ce qui le cause. : S Toute aide serait appréciée :)Programme pour vérifier un Palindrome
L'erreur se produit à la ligne 24 et il dit types incompatibles - trouvé vide mais attendu java.lang.String
public class programPalindrome
{
private String go()
{
Input in = new Input();
System.out.print("Enter Number: ");
return in.nextLine();
long number = in.nextLong();
String Palindrome = Long.toString(number); // converts the long into a string
String newAnswer = reverse(Palindrome);
String anotherAnswer = reverseCheck(Palindrome,newAnswer);
System.out.println("This is a Palindrome" + Palindrome);
}
// Check to see if the two argument Strings are the reverse of each
// other.
private String reverseCheck(String Palindrome, String newAnswer)
{
if (Palindrome.compareTo(newAnswer) == 0) {
return System.out.println("It is a palindrome");
}
else
{
return System.out.println("It is not a palindrome");
}
}
// Return a String which is the reverse of the argument String
private String reverse(final String Palindrome)
{
String result = new String();
int position = 0;
while (position < Palindrome.length())
{
result = new Character(newAnswer.charAt(position)).toString() + result;
position = position + 1;
}
return result;
}
public static void main(String[] args)
{
new programPalindrome().go();
}
}
pouvez-vous envoyer la trace de la pile? – vicatcu
Veuillez ajouter le message d'erreur et la ligne sur laquelle il se produit. –
Où obtenez-vous l'échec de la compilation? Pouvez-vous ajouter la pileTrace s'il vous plaît? – Luhar