当前位置:网站首页>Leetcode003 -- judge whether an integer is a palindrome number
Leetcode003 -- judge whether an integer is a palindrome number
2022-04-23 04:39:00 【singularityDZF】
import java.util.Scanner;
/**
* Give you an integer x , If x Is a palindrome integer , return true ; otherwise , return false .
* Palindrome number refers to positive order ( From left to right ) Reverse order ( From right to left ) Read all the same integers . for example ,121 It's palindrome. , and 123 No .
*
* Example 1:
* Input :x = 121
* Output :true
*
* Example 2:
* Input :x = -121
* Output :false
* explain : Read left to right , by -121 . Read right to left , by 121- . So it's not a palindrome number .
*
* Example 3:
* Input :x = 10
* Output :false
* explain : Read right to left , by 01 . So it's not a palindrome number .
*
* Example 4:
* Input :x = -101
* Output :false
*
*
* Tips :
* -231<= x <= 231- 1
*
*/
public class test03 {
public static void main(String[] args) {
System.out.print(" Please enter a number :");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
if(isPalindrome(num)){
System.out.println(num+" It's palindrome number !");
}else{
System.out.println(num+" Not palindrome !");
}
}
public static boolean isPalindrome(int x){
if(x < 0 || x%10==0 && x!=0){
return false;
}
else {
int reverNumber = 0;
while (x > reverNumber) {
reverNumber = reverNumber * 10 + x % 10;
x /= 10;
}
return x == reverNumber || x == reverNumber/10;
}
}
}
版权声明
本文为[singularityDZF]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230438035490.html
边栏推荐
- 229. 求众数 II
- QML进阶(五)-通过粒子模拟系统实现各种炫酷的特效
- [echart] démarrer avec echart
- Logger and zap log Library in go language
- Basic operation of sequence table
- KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
- 协程与多进程的完美结合
- Coinbase: basic knowledge, facts and statistics about cross chain bridge
- 记录一下盲注脚本
- leetcode003--判断一个整数是否为回文数
猜你喜欢
【论文阅读】【3d目标检测】Voxel Transformer for 3D Object Detection
指纹Key全国产化电子元件推荐方案
C语言:恶搞小游戏
Mysql50 basic exercises
Supplément: annotation
协程与多进程的完美结合
[AI vision · quick review of robot papers today, issue 32] wed, 20 APR 2022
AWS EKS添加集群用户或IAM角色
Single chip microcomputer serial port data processing (2) -- ucosiii + cyclic queue receiving data
383. 赎金信
随机推荐
AWS EKS 部署要点以及控制台与eksctl创建的差异
Experience summary and sharing of the first prize of 2021 National Mathematical Modeling Competition
VHDL implementation of 32-bit binary to BCD code
thymeleaf th:value 为null时报错问题
STM32 MCU ADC rule group multi-channel conversion DMA mode
无线键盘全国产化电子元件推荐方案
优麒麟 22.04 LTS 版本正式发布 | UKUI 3.1开启全新体验
leetcode002--将有符号整数的数字部分反转
阿里十年技术专家联合打造“最新”Jetpack Compose项目实战演练(附Demo)
Use recyclerview to realize left-right side-by-side classification selection
A new method for evaluating the quality of metagenome assembly - magista
What is the thirty-six plan
指纹Key全国产化电子元件推荐方案
shell wc (统计字符数量)的基本使用
在AWS控制台创建VPC(无图版)
上海航芯技术分享 | ACM32 MCU安全特性概述
【Pytorch基础】torch.split()用法
2019 is coming to an end, the longest day.
RC低通滤波器的逆系统
[AI vision · quick review of NLP natural language processing papers today, No. 32] wed, 20 APR 2022