小编Drk*_*ibs的帖子

如果 while 循环中的分支没有按预期执行

这是我正在使用的代码。此处引用的其他类已经过测试并且可以正常工作,但它们不应影响此处语句的功能。

import java.util.Scanner;

public class TransferTest 
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);

        double transferAmount;
        Account acct1 = new Account(100, null);
        Account acct2 = new Account(100, null);


        System.out.print("Choose an option: "
                + "\n1 <Enter>: to transfer from account 1 to account 2"
                + "\n2 <Enter>: to transfer from account 2 to account 1"
                + "\n3 <Enter>: to quit");
        int userOption = scan.nextInt();
        scan.nextLine();

        while(userOption != 3); 
        {
            if (userOption == 1)
            {
                System.out.print("You chose transfer …
Run Code Online (Sandbox Code Playgroud)

java if-statement while-loop nested-loops

0
推荐指数
1
解决办法
40
查看次数

标签 统计

if-statement ×1

java ×1

nested-loops ×1

while-loop ×1