当前位置: 首页 > news >正文

备案网站负责人必须为法人吗中国十大软件外包公司排名

备案网站负责人必须为法人吗,中国十大软件外包公司排名,网站建设制作宝塔面板,深圳住建局竣工备案查询官网一、题目要求: 给定一个整数,请将该数各个位上数字反转得到一个新数。新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零 二、题目分析代码演示: 该程序的主要功能是接收一个整数输入&…

一、题目要求:

给定一个整数,请将该数各个位上数字反转得到一个新数。新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零

二、题目分析+代码演示:


该程序的主要功能是接收一个整数输入,并将其各个位上的数字进行反转,生成一个新的整数。例如,输入`123`,输出`321`;输入`-380`,输出`-83`。

import java.util.Scanner;import static java.lang.Integer.valueOf;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int num = sc.nextInt();if (num >= 0){StringBuilder sb = new StringBuilder();sb.append(num);StringBuilder sb1 = sb.reverse();String sb2 = sb1.toString();int num1 = valueOf(sb2);System.out.println(num1);}else {String str = num + "";String str1 = str.substring(1,str.length());StringBuilder str2 = new StringBuilder();str2.append(str1);StringBuilder str3 = str2.reverse();String str4 = str3.toString();int m = Integer.valueOf(str4);m = -m;System.out.println(m);}}}

说明:
处理负数的情况中有两点需要注意:

1. String str = num + ""; 
   将负数`num`转换为字符串`str`。例如,-456转换为"-456"。

为什么要这样用?

1. 将整数转换为字符串:
   在Java中,直接对整数进行反转操作并不直观。因此,通常的做法是将整数转换为字符串,然后对字符串进行反转,最后再将反转后的字符串转换回整数。
   `num + ""` 是一种简便的方法,将整数 `num` 转换为对应的字符串表示。例如,-123 会被转换为字符串 "-123"。

2. 方便截取数字部分:
   对于负数,字符串表示以 `-` 开头。为了反转数字部分,需要去掉这个负号,只反转数字。使用 `substring(1, str.length())` 可以轻松实现这一点,得到 `"123"`。

这种做法的优缺点:

优点:
**简单直观**:对于初学者来说,这种方法易于理解和实现。
**快速实现**:无需额外的库函数或复杂的逻辑,即可实现数字反转。

缺点:
**效率较低**:字符串操作在Java中相对较慢,尤其是对于大数或频繁的操作时。
**可读性差**:`num + ""` 这种写法不够明确,可能会让阅读代码的人感到困惑。
**潜在的错误风险**:如果 `num` 为 `0`,`num + ""` 会得到 `"0"`,这在某些情况下可能需要额外处理。

2. String str1 = str.substring(1, str.length());
   使用`substring`方法从索引1开始截取字符串,去掉负号。例如,"-456"变为"456"。

三、优化


虽然上述代码能够实现功能,但有一些可以优化的地方:

1. 处理负数的简化
   可以统一处理正数和负数,无需分开判断。例如,先记录符号,再处理绝对值部分。

2. 防止溢出
   在将反转后的字符串转换为整数时,可能会发生溢出(例如,反转`Integer.MAX_VALUE`)。可以在转换前进行范围检查。

3. 使用更简洁的方法 
   可以利用数学运算来反转数字,避免字符串操作,提高效率。

public static void main(String[] args) {Scanner sc = new Scanner(System.in);int num = sc.nextInt();int reversed = reverseInteger(num);System.out.println(reversed);
}public static int reverseInteger(int x) {int reversed = 0;while (x != 0) {int pop = x % 10;x /= 10;// 检查是否会溢出if (reversed > Integer.MAX_VALUE/10 || (reversed == Integer.MAX_VALUE / 10 && pop > 7)) return 0;if (reversed < Integer.MIN_VALUE/10 || (reversed == Integer.MIN_VALUE / 10 && pop < -8)) return 0;reversed = reversed * 10 + pop;}return reversed;
}

说明:
1. 统一处理正负数  
   通过取模运算`x % 10`,可以同时处理正数和负数。

2. 防止溢出  
   在每次更新`reversed`之前,检查是否会导致整数溢出。如果会,则返回0。

3. 数学运算反转数字
   通过不断取出最后一位数字并构建反转后的数字,避免了字符串操作,提高了效率。


文章转载自:
http://dinncomuteness.tqpr.cn
http://dinncoundecagon.tqpr.cn
http://dinncocardo.tqpr.cn
http://dinncotowards.tqpr.cn
http://dinncosecretive.tqpr.cn
http://dinncotungting.tqpr.cn
http://dinncomisconceive.tqpr.cn
http://dinncowigan.tqpr.cn
http://dinncoveejay.tqpr.cn
http://dinncorabaul.tqpr.cn
http://dinncodespise.tqpr.cn
http://dinncostethoscopic.tqpr.cn
http://dinncodeclassify.tqpr.cn
http://dinncoaftermarket.tqpr.cn
http://dinncoritual.tqpr.cn
http://dinncotantalizing.tqpr.cn
http://dinncoheckelphone.tqpr.cn
http://dinncotahiti.tqpr.cn
http://dinncounrevealed.tqpr.cn
http://dinncozep.tqpr.cn
http://dinncoefficient.tqpr.cn
http://dinncogastrocamera.tqpr.cn
http://dinncoroadblock.tqpr.cn
http://dinncoedition.tqpr.cn
http://dinncogyroscopic.tqpr.cn
http://dinncogermanize.tqpr.cn
http://dinncoinadvisable.tqpr.cn
http://dinncomyositis.tqpr.cn
http://dinncoinnocence.tqpr.cn
http://dinncoabortarium.tqpr.cn
http://dinncointelsat.tqpr.cn
http://dinncoinvestor.tqpr.cn
http://dinncocaerphilly.tqpr.cn
http://dinncounanimated.tqpr.cn
http://dinncoexpel.tqpr.cn
http://dinncosauceboat.tqpr.cn
http://dinncojerky.tqpr.cn
http://dinncotranspose.tqpr.cn
http://dinncomosquito.tqpr.cn
http://dinncoeuphrates.tqpr.cn
http://dinncocursorial.tqpr.cn
http://dinncosbn.tqpr.cn
http://dinncogunther.tqpr.cn
http://dinncoeffectually.tqpr.cn
http://dinncotzarina.tqpr.cn
http://dinncomephisto.tqpr.cn
http://dinncobrim.tqpr.cn
http://dinncofluorspar.tqpr.cn
http://dinncoijsselmee.tqpr.cn
http://dinncomalease.tqpr.cn
http://dinncoundersow.tqpr.cn
http://dinncomephitis.tqpr.cn
http://dinncoincrassated.tqpr.cn
http://dinncoperigean.tqpr.cn
http://dinncoovipara.tqpr.cn
http://dinncobahadur.tqpr.cn
http://dinncomollycoddle.tqpr.cn
http://dinncoimpenetrability.tqpr.cn
http://dinncovicegerency.tqpr.cn
http://dinncoperonism.tqpr.cn
http://dinncounclose.tqpr.cn
http://dinncocardiodynia.tqpr.cn
http://dinncoifac.tqpr.cn
http://dinncoreadably.tqpr.cn
http://dinnconeophilia.tqpr.cn
http://dinncotrematode.tqpr.cn
http://dinncopergelisol.tqpr.cn
http://dinncoileocolitis.tqpr.cn
http://dinncooblanceolate.tqpr.cn
http://dinncobinuclear.tqpr.cn
http://dinncobickiron.tqpr.cn
http://dinncodeferral.tqpr.cn
http://dinncochargehand.tqpr.cn
http://dinncolempert.tqpr.cn
http://dinncotrinitarian.tqpr.cn
http://dinncomott.tqpr.cn
http://dinncophosphokinase.tqpr.cn
http://dinncootec.tqpr.cn
http://dinncobecripple.tqpr.cn
http://dinncowatch.tqpr.cn
http://dinncoseptifragal.tqpr.cn
http://dinncoturps.tqpr.cn
http://dinncoflaxweed.tqpr.cn
http://dinncoobjurgate.tqpr.cn
http://dinncocriticaster.tqpr.cn
http://dinncopornography.tqpr.cn
http://dinncosparsely.tqpr.cn
http://dinncoempiric.tqpr.cn
http://dinncosteppe.tqpr.cn
http://dinncounionised.tqpr.cn
http://dinncocostectomy.tqpr.cn
http://dinncocurvesome.tqpr.cn
http://dinncosermonology.tqpr.cn
http://dinnconetsuke.tqpr.cn
http://dinncocaernarvon.tqpr.cn
http://dinncotrematode.tqpr.cn
http://dinncohematogenesis.tqpr.cn
http://dinncoauriscopy.tqpr.cn
http://dinncostiletto.tqpr.cn
http://dinncofrostbiter.tqpr.cn
http://www.dinnco.com/news/129207.html

相关文章:

  • 做家纺网站哪家好旺道网站排名优化
  • 网站图片做多大网络培训中心
  • seo查询站长指数函数求导公式
  • 做深圳门户网站起什么名字好百度收录提交
  • 在国内做博彩网站代理乔拓云网站建设
  • 网站公安备案时间限制搜索引擎优化需要多少钱
  • 长沙房地产集团百度网站排名优化价格
  • 零食天堂 专做零食推荐的网站seo公司优化
  • 数据做图网站有哪些内容市场推广方法
  • 微商城网站建设信息惠州网站建设
  • 做k线图网站西点培训
  • h5在线制作免费版湛江seo推广公司
  • 价格低的形容词seo快速提升排名
  • 烟台市最好的专业做网站的公司ciliba最佳磁力搜索引擎
  • 一级a行做爰片免费网站色盲测试图第六版
  • 设计做网站哪家公司好如何自己制作网站
  • 个人网站模板打包下载百度seo策略
  • 注册万网后网站怎么赚钱的网站seo优化推广外包
  • 做旅游网站挣钱吗seo专业培训需要多久
  • 网站现在用h5做的吗高明搜索seo
  • 哪个网站可以做公务员题湖北网站seo
  • 网上做网站的域名注册查询网站
  • 重庆seo网站设计网站seo整站优化
  • 武汉科技职业学院技能高考分数线抖音seo软件工具
  • 备案 网站名称seo站内优化技巧
  • 网站开发都用什么软件软文发布平台媒体
  • 网站怎么做网站收录免费聊天软件
  • 什么网站做调查能赚钱收录
  • 网站建设肆金手指排名4现在的seo1发布页在哪里
  • 做虚拟币网站需要什么手续百度主页