“Palindrome in Java” Code-Antworten

Überprüfen Sie Palindrome in Java

class Solution {
    public boolean isPalindrome(int x) {
        if(x < 0)
            return false;

        return x == reverseNum(x);

    }
    private static int reverseNum(int num){
        int rev = 0;
        while(num>0){
            int digit = num%10;
            rev = (rev * 10) + digit;
            num = num/10;
        }
        return rev;
    }
}
Glorious Gazelle

Ganzzahl Palindrome in Java

 public boolean isPalindrome(int x) {
        String str = Integer.toString(x);
        String reverse =  new StringBuilder(str).reverse().toString();
        return  str.equals(reverse)?true:false;}
Kirk-Patrick Brown

So überprüfen Sie Palindrome in Java

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int num = input.nextInt();
        int temp = num;

        int rev = 0;
        while (num > 0) {
            rev = rev * 10 + num % 10;
            num /= 10;
        }
        System.out.println(temp==rev?"palindrome":"not palindrome");
    }
Chathumal Sangeeth

ist Palindrome Java

public static boolean checkPalindrome(String str)
{     
 
    int len = str.length();

    for(int i = 0; i < len / 2; i++)  {
        if (str.charAt(i) != str.charAt(len - i - 1))
            return false;
    }
    return true;
}
Filthy Fox

Ganzzahl Palindrome in Java

 public boolean isPalindrome(int x) {
        String str = Integer.toString(x);
        String reverse =  new StringBuilder(str).reverse().toString();
        return  str.equals(reverse)?true:false;
     }
Kirk-Patrick Brown

Palindrome in Java

package com.candidjava; import java.util.Scanner; public class PalindromeUptoN{	public static void main(String[] args)	{		int n, b, rev = 0;		Scanner sc = new Scanner(System.in);		System.out.println("Enter the Palindrome No N:");		int N = sc.nextInt();		System.out.print("Palindrome numbers from 1 to N:");		for (int i = 1; i <= N; i++)		{			n = i;			while (n > 0)			{				b = n % 10;				rev = rev * 10 + b;				n = n / 10;			}			if (rev == i)			{				System.out.print(i + " ");			}			rev = 0;		}	} }
sree_007

Ähnliche Antworten wie “Palindrome in Java”

Fragen ähnlich wie “Palindrome in Java”

Weitere verwandte Antworten zu “Palindrome in Java” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen