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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!