Question

Here is the code I am supposed to Analyze: // If we want to use the...

Here is the code I am supposed to Analyze:


// If we want to use the Scanner class (type) to get user input, we need
// to import the following Java package that includes the Scanner class
// definitions. We do not have to add an import statement to use the
// print() or println() methods of the System object, because they
// are built in.

import java.util.Scanner;

public class PRG420Week1_AnalyzeAssignment {

/* The main() method you see below is special. It tells the Java interpeter to "start here."
EVERY JAVA APPLICATION OR APP MUST HAVE A MAIN METHOD CALL THAT LOOKS LIKE THIS:
public static void main(String[] args) {}
  
The "meat" of the program goes between the curly braces.
The main() method can take an array of strings (called args, which is short for "arguments").
However, in this case, we are not passing any arguments to the main() method and we are not
referencing the args variable anywhere in the body of the main() method. We are simply
telling the Java interpreter to begin running the first line within the curly braces and
keep going until the last line within the curly braces.
*/

public static void main(String[] args) {
  
// Display a message on the console using the println() method.
System.out.println("Display the line."); // Display the string "Display the line"
  
// Similar result to above--only this time, we will call the println() method with a variable.
String myStringVariable; // Declare a variable of type String called myStringVariable
myStringVariable = "Hello, world!"; // Assign string value "Hello, world!" to myStringVariable
System.out.println(myStringVariable); // Display this new string on the console
  
//Similar result to the two above--only this time, we will ask for a string from the user
//and use that string to format and display a greeting on the console.
Scanner myInputScannerInstance = new Scanner(System.in); // Create a usable instance of an input device (which for most people is a keyboard)
System.out.print("Please type a word and then press Enter: "); // Prompt user for input. print() does not add a carriage return.
// Capture first word user types in (ignore everything after the first space) and assign it to variable sentenceYouTyped
String sentenceYouTyped = myInputScannerInstance.next();
// Construct and display the message. The println() method adds a carriage return.
System.out.println("You just typed in this word: |" + sentenceYouTyped + "|");
}
  
}

Here are the questions I am being asked:

Carefully read through the code line by line, then answer the following questions in a Microsoft® Word document:

  1. What syntax signals a Java™ comment? (In other words, what symbol(s) tell the Java™ compiler not to process certain text?)
  2. Type the line(s) of code that accept user input.
  3. Type the line(s) of code that process user input.
  4. Type the line(s) of code that produce output.
  5. Type the result this program would produce if a user, when prompted, responded by typing "everyone" and then hit Enter.
  6. Type the result this program would produce if a user, when prompted, responded by typing in "Mickey Mouse" and hit Enter.
  7. Type the result this program would produce if a user, when prompted, responded by typing "Benjamin Franklin" and hit Enter.

Homework Answers

Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

1,Java Comment :

  • // is used for single line comment
  • /**/ is used for multi line comment.

2.Line of the code that accept user input :

  • Scanner myInputScannerInstance = new Scanner(System.in);
  • Scanner class is required when input is taken by user.

3.line(s) of code that process user input :

  • String sentenceYouTyped = myInputScannerInstance.next();
  • this line will read the input entered by user in the variable named sentenceYouTyped

4. the line(s) of code that produce output.:

  • System.out.println("You just typed in this word: |" + sentenceYouTyped + "|");
  • Above line will display user input on the console

5.Screen when user enter everyone

6.Screen when user enter Mickey Mouse

7.Screen when user enter Benjamin Franklin

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Hello, I am trying to create a Java program that reads a .txt file and outputs...
Hello, I am trying to create a Java program that reads a .txt file and outputs how many times the word "and" is used. I attempted modifying a code I had previously used for counting the total number of tokens, but now it is saying there is an input mismatch. Please help! My code is below: import java.util.*; import java.io.*; public class Hamlet2 { public static void main(String[] args) throws FileNotFoundException { File file = new File("hamlet.txt"); Scanner fileRead =...
Read in a file "numbers.txt" into a Java program. Sum up all the even numbers over...
Read in a file "numbers.txt" into a Java program. Sum up all the even numbers over 50. Print the result to the console using System.out.println(); The file will only have numbers. code below import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Scanner; public class ReadingFiles { public static void main(String[] args) throws FileNotFoundException { System.out.println(totalEven); } }
THIS IS FOR JAVA I have to write a method for a game of Hangman. The...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The word the user is trying to guess is made up of hashtags like so " ###### " If the user guesses a letter correctly then that letter is revealed on the hashtags like so "##e##e##" If the user guesses incorrectly then it increments an int variable named count " ++count; " String guessWord(String guess,String word, String pound) In this method, you compare the character(letter)...
Using JAVA For this assignment, you will analyze code that uses a file input stream and...
Using JAVA For this assignment, you will analyze code that uses a file input stream and a file output stream. Read through the linked Java™ code. In a Microsoft® Word document, answer the following questions: Could this program be run as is? If not, what is it lacking? Does this program modify the contents of an input stream? In what way? What are the results of running this code? ********************************************** CODE TO ANALYZE  ******************************************************** /********************************************************************** *   Program:   Datasort *   Purpose:   ...
using java LO: (Analyze) Students will fix a loop that runs forever. This program runs the...
using java LO: (Analyze) Students will fix a loop that runs forever. This program runs the countdown sequence for a rocket launch. However, it seems to loop infinitely. Fix the program so it counts down and terminates properly. starter code : import java.util.Scanner; /* * Counts down to a blastoff, starting from a given number. */ public class Countdown {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int countdown = 0;...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input and output with the Java console. Setup: Create a class called ConsolePractice with a main method. Create a static field in your class that stores a scanner object. You will use this scanner for all user input. private static Scanner scanner = new Scanner(System.in); Part A: Create a static method called “divide”. Your method should do the following: Accept two integers as parameters, a...
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the...
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the area of a rectangle * based on the width and length entered by the user. */ public class RectangleArea2 {             public static void main(String[] args) { int length; //longer side of rectangle             int width; //shorter side of rectangle int area; //calculated area of rectangle Scanner input = new Scanner(System.in);                               System.out.print("Enter the length: ");            length = input.nextInt(); System.out.print("Enter...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average of a set of numbers */ public class AverageValue { public static void main(String[] args) { final int SENTINEL = 0; int newValue; int numValues = 0;                         int sumOfValues = 0; double avg; Scanner input = new Scanner(System.in); /* Get a set of numbers from user */ System.out.println("Calculate Average Program"); System.out.print("Enter a value (" + SENTINEL + " to quit): "); newValue =...