Question
Java 1. Type a statement that reads a user-entered integer into variable numUsers. Assume scnr already exists. 2. Write a statement that outputs variable numCars
Java
1. Type a statement that reads a user-entered integer into variable numUsers. Assume scnr already exists.
2.
Write a statement that outputs variable numCars as follows. End with a newline.
There are 99 cars.
Note: Whitespace (blank spaces / blank lines) matters; make sure your whitespace exactly matches the expected output.
public class OutputExample {
public static void main (String [] args) {
int numCars = 99;
Scannerscnr=new Scanner(System.in);
numCars=scnr.nextInt();
System.out.println(numCars);
return;
}
}
3. Type the statements. Then, correct the one syntax error in each statement. Hints: Statements end in semicolons, and string literals use double quotes.
System.out.printl("Predictions are hard."); System.out.print("Especially '); System.out.println("about the future."). System.out.println("Num is: " - userNum);
import java.util.Scanner;
public class Errors { public static void main(String [] args) { int userNum = 5;
System.out.println ("Predictions are hard. "); System.out.print("Especially '"); System.out.print("about the future."); System.out.println("Num: "- userNum); return; } }
Errors.java:10: operator - cannot be applied to java.lang.String,int System.out.println("Num: "- userNum); ^ 1 error
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started