Question: 297914.1732840 LAB ACTIVITY 20.23.1: Prog1-Ch1: Basic input and output with variables-b 0/100 Downloadable files OutputWithvars.java Download Output With Vars.java Load default template... 1 // Programmer:


297914.1732840 LAB ACTIVITY 20.23.1: Prog1-Ch1: Basic input and output with variables-b 0/100 Downloadable files OutputWithvars.java Download Output With Vars.java Load default template... 1 // Programmer: Your name 2 // Class, Section and Term: 3 // Purpose: Input and output of some values 4 5 // Import the Scanner Class for creating respective 6 // Scanner objects to perform input operations. 7 import java.util.Scanner; 8 public class OutputWithVars { 9 public static void main(String[] args) { 10 // Create the Scanner object, scnr, to perform input 11 // operations. 12 Scanner scnr - new Scanner(System.in); 13 14 // Declare the identifiers 15 int userNum; 16 int userNum2; 17 18 // Input values, perform operations and output results 19 System.out.println("Enter integer:"); userNum = scnr.nextInt(); 21 22 23 24 25 scnr.close(); 26 27 } 28 20 Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box 20.23 Prog1-Ch1: Basic input and output with variables-b Step by step, extend the given program to produce the indicated results. *NOTE: A statement such as "userNum = scnr.nextInto;" WAITS for a user to enter an input integer value (followed by the Enter key), grabs the value and stores it in the variable userNum. Before the above statement, you ought to display a message (or prompt) asking the user to enter a value. You can do so by using a statement such as System.out.println("Enter integer:");". If you do not do so, the computer will wait for an input without you knowing why a cursor is showing and nothing else is happening. After you complete your program and submit it for grading, the computer will use its input data to test your program. In other words, you will not see any of the input values displayed, which is OK. Do not exhaust the maximum number of allowed submissions. Do all your programming and testing in "Develop mode" before submitting your program using "Submit mode" (1) Output the value entered by the user. Enter integer: 4 You entered: 4 Extend the program to output the value of the input squared and cubed. _Hint: Compute squared as userNum * userNum. Enter integer: 4 You entered: 4 4 squared is 16 And 4 cubed is 64!! (3) Extend the program to get a second user input into userNum2. Output the sum and the product of the two numbers. Enter integer: 4 You entered: 4 4 squared is 16 And 4 cubed is 64!! Enter another integer: 4 + 5 is 9 4 * 5 is 20
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
