帮我翻译成do [英] Help me to translate it into do while

查看:96
本文介绍了帮我翻译成do的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉不遵守此处的条款。现在我得逆转但我的问题我必须转换为什么同时你可以帮助我..这是代码





Sorry for not following the terms here. Now I got to reverse but my problem I have to convert the while into do while can you help me.. Here's the code


<html>
<head></head>
 <script type ="text/javascript">

<html>
<head></head>
 <script type ="text/javascript">


	       var reverse = 0; 
                 var n = prompt("Enter reverse numbers: "); 
		while (n != 0) { 
                reverse = reverse * 10;
		reverse = reverse + parseInt(n%10); 
		n = parseInt(n/10); } 
		document.write(" The reverse of the number: "+reverse);	


</script>
<body>

</body>
</html>

and here's what I've done so far

var reverse = 0;
		
			
		var n = prompt("Enter reverse numbers: "); 
		
do {
reverse = reverse * 10;
		reverse = reverse + parseInt(n%10); 
		n = parseInt(n/10); } 
		document.write(" The reverse of the number: "+reverse);

}while(n != 0);}


When I run this it output a blank. Don't know where I got mistake. 
Thanks to your help God bless

推荐答案

你不能对字符串使用数学运算(parseInt(n%10))。首先需要将整个输入字符串转换为整数,然后执行相反的操作。或者,您可以将字符串拆分为一个字符数组,然后将其反转。
You cannot use mathematical operations on strings (parseInt(n%10)). You first need to convert the entire input string into an integer and then do the reverse operation. Alternatively you could just split the string into an array of characters and then reverse them.


这篇关于帮我翻译成do的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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