Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java method exercises

import java.util.Scanner;

public class TestPalindrom
{
    public static void main(String[] args)
    {
        Scanner console = new Scanner(System.in);
     
        int num;

        System.out.print("Enter a number: ");
        num = console.nextInt();
        
        if(isPalindrom(num))
        {
            System.out.println("Number is palindrom");
        }
        else
        {
            System.out.println("Number is not palindrom");
        }
    }


    public static boolean isPalindrom(int number)
    {
        int temp = number;
        int remainder;
        int reverse = 0;
        
        while(temp > 0)
	{
            remainder = temp % 10;
            temp = temp / 10;
            reverse = reverse * 10 + remainder;
	}
        
        return reverse == number;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: extend vs implement in java 
Java :: java string stringbuilder remove trailing comma 
Java :: arduino convert byte array to string 
Java :: @entity annotation in spring boot 
Java :: when does black jack happens 
Java :: how to call a void method from another class in java 
Java :: find power of number in method java 
Java :: Java if (if-then) Statement 
Java :: add integers java 
Java :: java hello world program 
Java :: Java Lambda Expressions with parameters 
Java :: java swing date picker 
Java :: java read all text from file 
Java :: coin flip in java 
Java :: how do I test the reverse method in java using jest 
Java :: java.lang.NoClassDefFoundError: net/sf/cb2xml/def/IItem 
Sql :: foreign key set 0 
Sql :: postgres active connections 
Sql :: installing mysql 
Sql :: safe update mode in mysql 
Sql :: pl sql output 
Sql :: create database if not exists 
Sql :: sql server beginning of month 
Sql :: cast string to datetime mysql 
Sql :: mysql first day of year 
Sql :: sql server last executed query 
Sql :: psql filed name alter 
Sql :: how to group by month using sql server 
Sql :: how to check when a stored procedure was last modified in sql server 
Sql :: InnoDB: page_cleaner: 1000ms intended loop took 7742ms. The settings might not be optimal 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =