Why my code for checking if a number is a palindrom won't work?

后端 未结 5 1646
逝去的感伤
逝去的感伤 2021-01-29 06:28

My Java code is here:

import java.util.Scanner;
public class task2 {
    public static void main(String args[])  {
        System.out.print(\"Input a 3 digit int         


        
5条回答
  •  情歌与酒
    2021-01-29 07:12

    The problem is that in the course of processing the value of x is being changed from what was originally input - it always ends up as 0.

    So, you have to preserve the input value, like so:

    Scanner scan = new Scanner(System.in);
    int original = scan.nextInt();
    int x = original;
    

    and then use the original value for the final comparison, like so:

    if (original == isPalindrome){
    

提交回复
热议问题