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

后端 未结 5 1742
逝去的感伤
逝去的感伤 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:22

    This is because the value of x is getting changed finally.Which is not the original number at the end of the program. SO take another variable just below x like: int y = x; And at the end while using "if" condition use this value of y for comparison rather than using x. It will run perfectly.

    int x = scan.nextInt();

    int y=x;

    if (y == isPalindrome) Add new variable like this.

提交回复
热议问题