Purpose: I am trying to stop and let the user input another value but my result is Enter integer: You have entered 2 2 squared is 4 And 2 cubed is 8 Enter another integer: meaning my first part worked but... Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at OutputWithVars.main(OutputWithVars.java:18) meaning that the second scnr.nextInt(); I used didn't work
import java.util.Scanner;
public class OutputWithVars {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int userNum;
int userA;
int userB;
System.out.println("Enter integer:");
userNum = scnr.nextInt();
userA = userNum * userNum;
userB = userNum * userNum * userNum;
System.out.printf("You have entered %d", userNum);
System.out.printf("\n%d squared is %d", userNum, userA);
System.out.printf("\nAnd %d cubed is %d", userNum, userB);
System.out.println("\nEnter another integer:");
int user = scnr.nextInt();
System.out.printf("%d", user)
Purpose: I am trying to stop and let the user input another value but my result is
Enter integer: You have entered 2 2 squared is 4 And 2 cubed is 8 Enter another integer: meaning my first part worked but...
Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at OutputWithVars.main(OutputWithVars.java:18)
meaning that the second scnr.nextInt(); I used didn't work
Trending now
This is a popular solution!
Step by step
Solved in 2 steps