Java If-Else语句执行不正确
这是我的代码,顺便说一句,我不是要求免费修复,我是在找人帮助我,解释我的错误。提前谢谢Java If-Else语句执行不正确,java,Java,这是我的代码,顺便说一句,我不是要求免费修复,我是在找人帮助我,解释我的错误。提前谢谢 * Psuedocode: * 1. Ask the user if they want to enter a number or if they want the computer to select a random number. * 2. Based on the user selection, Ask the user for a number or generate a rando
* Psuedocode:
* 1. Ask the user if they want to enter a number or if they want the computer to select a random number.
* 2. Based on the user selection, Ask the user for a number or generate a random number.
* 3. Read the number from the user (Skip the step if a random number is generated)
* 4. Check if the number is 1 digit or 2 digit or 3 digit or 4 digit
* 5. if it is 1 digit then check if the cube of number equals the number
* 6. else if it is 2 digit, get the cube of first and second digits and then sum them up and check if the number is equal to the sum.
* 7. else if it is 3 digit, get the cube of first, second and third digits and then sum them up andcheck if the number is equal to the sum.
* 8. if it is 4 digit, get the cube of first, second, third and fourth digits and then sum them up andcheck if the number is equal to the sum.
* 9. else tell the user that the number they have entered is not within 9999
* 10. Print a closing message saying if the number is an Armstrong number or not.
* 11. Print a goodbye statement.
*/
我选择的随机生成器方法不起作用。它仅将1和2显示为armstrong数字或非armstrong数字,但不为该代码中的选项2生成随机数
int choice = 0;
Random rand = new Random();
// you need to assign something to choice before the next line
// maybe choice = rand.nextInt (); ?
if(choice == 1)
int choice=0后跟ifchoice==1。。。那永远不会是真的。。。后跟else ifchoice==2。。。不,也不是真的。当我取消初始化choice时,if else语句中有一个编译器错误,它被取消初始化。基本上,在测试它的值之前,不会从输入中分配choice。
int choice = 0;
Random rand = new Random();
// you need to assign something to choice before the next line
// maybe choice = rand.nextInt (); ?
if(choice == 1)