我去。:)我是一个完全的初学者,所以我一开始就把这一切都弄清楚了。:) import java.util.Scanner; public class Program3 { public static void main(String[] args)

我去。:)我是一个完全的初学者,所以我一开始就把这一切都弄清楚了。:) import java.util.Scanner; public class Program3 { public static void main(String[] args) ,java,while-loop,switch-statement,do-while,Java,While Loop,Switch Statement,Do While,我去。:)我是一个完全的初学者,所以我一开始就把这一切都弄清楚了。:) import java.util.Scanner; public class Program3 { public static void main(String[] args) { double operandOne; double operandTwo; char newLine = '\n'; Scanner input = new Scanner (System.in);


我去。:)我是一个完全的初学者,所以我一开始就把这一切都弄清楚了。:)
import java.util.Scanner;

public class Program3 
{

public static void main(String[] args) 
{

    double operandOne;
    double operandTwo;
    char newLine = '\n';
    Scanner input = new Scanner (System.in);

    //"input" is an object which calls for input from the keyboard.

        System.out.print("This program will request values for two operands ");
        System.out.println("and perform an arithmetic operation of your choice on them.");
        System.out.println(newLine + "Please enter a value for the first operand.");
        operandOne = input.nextDouble();

        System.out.println("Thank you.  Please enter a value for the second operand.");
        operandTwo = input.nextDouble();

        // This section explains what's going on to the user and requests input for the operands.

        if ( operandTwo == 0 )
        {

            System.out.print("You will not be able to perform division if the ");
            System.out.println("second operand is zero!");
            System.out.println(newLine + "Please choose an option:");
            System.out.println("Type 1 to select a new value for the second operand.");
            System.out.println("Type 2 to continue with a value of zero.");

            // You can't divide by zero!  Are you SURE you want to use that number?

            int reallyWantZero = input.nextInt();
            do
            {   
                System.out.println(newLine + "You must type either 1 or 2 and press enter.");
                reallyWantZero = input.nextInt();
            }

            while ((reallyWantZero < 1) || (reallyWantZero > 2));
            {
                switch (reallyWantZero)
            {
                case 1:
                    System.out.println(newLine + "Please enter a new value for the second operand.");
                    operandTwo = input.nextDouble();
                break;
                case 2:
                    System.out.println(newLine + "Okay, we will proceed.");
                    break;
            }
            }
        }
while ((reallyWantZero < 1) || (reallyWantZero > 2));
                {
                    System.out.println(newLine + "You must type either     1 or 2 and press enter.");
                    reallyWantZero = input.nextInt();
                }               
                switch (reallyWantZero)
                {
                    case 1:
do
{   
    System.out.println(newLine + "You must type either 1 or 2 and press enter.");
    reallyWantZero = input.nextInt();
} 
while ((reallyWantZero < 1) || (reallyWantZero > 2));
while ((reallyWantZero < 1) || (reallyWantZero > 2)) {
    System.out.println(newLine + "You must type either 1 or 2 and press enter.");
    reallyWantZero = input.nextInt();
}
while (reallyWantZero != 1 && reallyWantZero != 2) {
    System.out.println("enter 1 or 2");
    reallyWantZero = input.nextInt();
}

//do stuff here with that info