Write a statement that outputs variable userNum. End with a newline. Program will be tested with different input values. 1 import java.util.Scanner; 2 3 public class VariableOutput { 4 public static void main (String[] args) { 5 int userNum; 6 Scanner scnr = new Scanner(System.in); 7 userNum = scnr.nextInt(); 8 /* Your solution goes here */ 9 10 } 11} 12 13 14
Added by Christopher S.
Close
Step 1
First, we need to declare the variable `userNum` of type `int` before using it. So, we add the line `int userNum;` before the `main` method. Show more…
Show all steps
Your feedback will help us improve your experience
Pritesh Ranjan and 81 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Supreeta N.
Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 Edit with the following code: import java.util.Scanner; public class NumberPrompt { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int userInput; do { System.out.println("Enter a number (<100): "); userInput = scnr.nextInt(); } while (userInput >= 100); System.out.println("Your number < 100 is: " + userInput); } }
Willis J.
Write code that uses the input string stream inSS to read input data from string userInput; and updates variables userMonth, userDate, and userYear. Sample output if the input is "Jan 12 1992": Month: Jan Date: 12 Year: 1992 import java.util.Scanner; public class StringInputStream { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Scanner inSS = null; String userInput; String userMonth; int userDate; int userYear; userInput = scnr.nextLine(); inSS = new Scanner(userInput); userMonth = inSS.next(); userDate = inSS.nextInt(); userYear = inSS.nextInt(); System.out.println("Month: " + userMonth); System.out.println("Date: " + userDate); System.out.println("Year: " + userYear); } }
Derrick D.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD