Question: Lab 4.1: Input Using a Scanner Let's first write a program so that it uses basic (Scanner-based) input, and basic output. Create a new Eclipse
Lab 4.1: Input Using a Scanner
Let's first write a program so that it uses basic (Scanner-based) input, and basic output.
Create a new Eclipse project named CPS_150_Lab4_1
Add a Main class (with a main method).
Type (or copy/paste) in the highlighted code and then complete and run the following program:
import java.util.Scanner; /* Complete the following program that prompts the user to enter two integers, then outputs which integer is smaller, and which integer is larger. */ public class Main { public static void main(String[] args) { Scanner kbd = new Scanner( System.in ); // TODO: declare input1 and input2 as integers, each initialized to 0 // TODO: declare minInput and maxInput as integers, each initialized to 0 // TODO: prompt the user for the first input value // TODO: get the value of input1 as user input, using the kbd Scanner // TODO: prompt the user for the second input value // TODO: get the value of input2 as user input, using the kbd Scanner // set minInput to the smaller of input1 and input2 minInput = Math.min(input1, input2); // set maxInput to the larger of input1 and input2 maxInput = Math.max(input1, input2); // TODO: output the smaller integer // TODO: output the larger integer
} // end main method } // end Main class
Then. test the program using the inputs:
- 12 and 23, and
- 23 and 12.
Lab 4.2: Input Using an Input Dialog
Now, let's write the program that implements input using more graphical dialog boxes.
Create a new Eclipse project named CPS150_Lab4_2
Add a Main class (with a main method).
Type (or copy/paste) in the highlighted code and then complete and run the following program:
Then. test the program using the inputs:
- 12 and 23, and
- 23 and 12.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
