Question: My code seems to be right.. will someone tell me what I am doing wrong please.. this is my code. import java.util.Scanner; public class OutputWithVars
My code seems to be right.. will someone tell me what I am doing wrong please.. this is my code.
import java.util.Scanner;
public class OutputWithVars { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int userNum = 0; int userNum2 = 0; userNum = scnr.nextInt(); System.out.println("Enter integer: " + userNum); System.out.println("You entered: " + userNum); System.out.println(userNum + " squared is " + userNum * userNum); System.out.println("And " + userNum + " cubed is " + userNum * userNum * userNum + "!!");
System.out.println("Enter another integer: "); userNum2 = scnr.nextInt(); System.out.println(userNum + " + " + userNum2 + " is " + (userNum + userNum2)); System.out.println(userNum + " * " + userNum2 + " is " + (userNum * userNum2)); return; } }

1.13 Warm up: Basic output with variables (Java) 1.13 Warm up: Basic output with variables (Java) 1.12 Warm up. Hello world (Java) yster out.arintinou enzered: uerhun 1.13 Warm up: Basic output with variables (Java) This zylab achinty is intondod for students to proparo for a fagerpogamming assignmont Wam up exercises aree tyricwWy simpler ad warth fewr pifs thian a fu progranmingsinment Wam u e ercises are ideally suited ur persun acheduled lab !reeling ur as aer practice The lasi eectiun Systes.out.erintin Enter arothe inteser sertiu-c.ntint Saun.uul.rintLnuaurium-tun(uaurNum aL-2 Systee.out.r1ntIn(usernun . . . ', + usertur2+ "-5 . + (UserNun-use-M#2: A variablelie userNum can store ave like an ineger Fxtend the given prrgram to print userNum values ds irdicaled. Subi for 2 pains) 1)Output the user's input uut In Develpmede, ycu can run your pregram as oten as you'd like, bel values tesited in th first box below, then click "Run pregnan" arni al Develop ter integer: 4 cntered: 4 2) Extend to outout the input squarod and cubod. Hint Computo sqwarod as uscrNun usorNum. (Submit RUN PROGRAM r2paints, sa 4 points tntal) Enter program input (optional) Enter integer: 4 cntered: 4 4 squared is 1s And 4 cubed is 64!! 3) Extend to get a second user input into userNum2 Ouput sum and product (Submit for 1 paint, so5 ints tatal) Culput'with Vars.java (Your program) Enter integer: 4 You entered: 4 4 squared i: 16 And 4 cubed is 64!! Enter another integer: 5 4+5 is 9 Program output cisplayed here Ente" integer"; You enterpd:4 4 squared is 1 And 4 cubed is 64!! Enter another integer Exceptian in thread "main Java.utii.NosuchtlomontExceptien .5s 20 at java.util.Sconner.throFor Scanner-java: 852 at java.utilStanner next Scanner iava: 1485) at java. ut11 . Sranner. not Tnt( 5cannerjava: 211 7) at Java.util.Scanner.nextInt(Scannar.java: 2876) at CutputMithVars.mainOutputwithvars.java:23) umI1.13.1: Warm up: Basic output with variables (Java)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
