Question: 1. Which of the following code is valid to create a Scanner object? Please keep in mind the Java coding standard. A.

1. Which of the following code is valid to create a Scanner object?

Please keep in mind the Java coding standard.
    A.     Scanner String = new Scanner(System.in);
    B.     Scanner public = new Scanner(System.in);
    C.     Scanner myScanner = new Scanner(System.in);
    D.     Scanner reader = new Scanner(System.in);
    E.     Scanner input = new Scanner(System.in);

2. In the following code, which lines have code that does not adhere to the Java coding standard?

1   public class myProgram {
2      public static void main(String[] args) {
3
4         //declare variables and output text about spaghetti
5         double money = 20.00;
6         final double costOfSpaghetti = 4.95;
7         System.out.println("You want some spaghetti?");
8         System.out.println("Okay. Here's your spaghetti.");
9         System.out.println("Now you have $" + (money-costOfSpaghetti));
10
11   }
12   }
    A.     1
    B.     2
    C.     3
    D.     4
    E.     5
    F.     6
    G.     7
    H.     8
    I.     9
    J.     10
    K.     11
    L.     12
    M.     The entire code adheres to the coding standard.

3. What is the output of the following code?

double myNumber = 123.4567;
System.out.printf("%10.3f", myNumber);
    A.     0000123.457
    B.     000123.457
    C.     123.4570000
    D.     0000123.456
    E.     123.4560000
    F.     000123.456

4. In the following code, which lines have code that does not adhere to the Java coding standard?

1   public class myProgram {
2      public static void main(String[] args) {
3        
4         //Declare variables
5         int age = 20;
6         double ageInDogYears = 140;
7        
8         //Print out age and age in dog years.
9         System.out.print("I am " + age + "years old.");
10        System.out.print("In dog years, I would be " + ageInDogYears );
11        System.out.print(" years old.");
12  }
13  }
    A.     1
    B.     2
    C.     3
    D.     4
    E.     5
    F.     6
    G.     7
    H.     8
    I.     9
    J.     10
    K.     11
    L.     12
    M.     13
    N.     The entire code adheres to the coding standard.

5. In the following code, which lines have code that does not adhere to the Java coding standard?

1   /*
2    * My program prints my name.
3    *
4    *@author    Manuel, Nikki
5    *@date      January 1, 1900
6    *@bugs      No bugs.
7   */
 
    A.     1
    B.     2
    C.     3
    D.     4
    E.     5
    F.     6
    G.     7
    H.     The entire code adheres to the coding standard.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

1correct answers are Scanner input new ScannerSystemin Scanner myScanner new ScannerSystemin Scanner String new ScannerSystemin Scanner reader new Sca... View full answer

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 Programming Questions!