使用“while”使用java程序反转数字的数字? [英] using "while" reverse the digits of the number using java programme?

查看:226
本文介绍了使用“while”使用java程序反转数字的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用while使用java程序反转数字的数字?

using "while" reverse the digits of the number using java programme?

推荐答案

请查看问题的评论是PIEBALDconsult,Kornfeld Eliyahu Peter和Richard Deeming ;它们非常合理。



也许你还需要一些小提示。这里的要点是将您的号码转换为字符串。只有数字的字符串表示具有数字,实际上只是字符。具体如下:

Please see the comment to the question be PIEBALDconsult, Kornfeld Eliyahu Peter and Richard Deeming; they are very reasonable.

Perhaps you still need some minor hints. Main point here is to convert your number to a string. Only a string representation of a number has "digits", which are actually just the characters. This is how:
var myNumber = 2319; // or anyting
var myString = new String(x);
// this is another way to do the same:
myString = "" + myNumber;



现在你需要使用相反顺序从 myString 中获取的字符创建另一个字符串。你已经知道连接运算符+。对于循环的条件,您将需要字符串属性 length 。请参阅:

String - JavaScript | MDN [ ^ ]。



在循环时,您不必使用; for 循环可能更合理,因为你当然需要通过索引访问字符。但重要的一点是:当你问一个关于如何做某事的问题时,不要把它与你对如何去做的理解混在一起。另一方面,到目前为止,最好显示 你尝试了什么



-SA


Now you need to create another string populated with characters taken from myString in reverse order. You already know concatenation operator, +. For the conditions for your loop you will need the string property length. Please see:
String — JavaScript | MDN[^].

You don't have to use while loop; for loop might be more reasonable, because you certainly will need to access characters by index anyway. But important point here is: when you ask a question on how to do something, don't mix it up with your understanding on how to do it. From the other hand, it would be better to show what have you tried so far?

—SA


这篇关于使用“while”使用java程序反转数字的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆