Question

This assignment requires comments for each line explaining why it is necessary for the coding to...

This assignment requires comments for each line explaining why it is necessary for the coding to run properly. I understand most of it but not all.

import java.util.Scanner; // comment here:

public class Age { // comment here:

      public static void main (String[] args){ // comment here:

final int MINOR = 21;//

Scanner scan = new Scanner (System.in); // comment here:

System.out.print ("Enter your age: "); // comment here:

int age = scan.nextInt();//comment here:

System.out.println ("You entered: " + age); // comment here:

if (age < MINOR){// comment here:

System.out.println ("Youth is a wonderful thing. Enjoy."); // comment here:

}

System.out.println ("Age is a state of mind.");// comment here:

                             }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner; // importing Scanner class to read the values from user

public class Age { // declaring the clasas

   public static void main (String[] args){ // writing the main method

       final int MINOR = 21;// declared constant value as this is fixed value we made it as final

       Scanner scan = new Scanner (System.in); // creating scanner object to read values from user:

       System.out.print ("Enter your age: "); // asking the age for user:

       int age = scan.nextInt();//reading the user entered age into age variable:

       System.out.println ("You entered: " + age); // printing back to user what they entered:

       if (age < MINOR){// checking age if it is less than the MINOR:

           System.out.println ("Youth is a wonderful thing. Enjoy."); // printing the message regarding the youth

       }

       System.out.println ("Age is a state of mind.");// printing message regarding the minor

   }

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
This assignment requires comments for each line explaining why it is necessary for the coding to...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Provide comments for this code explaining what each line of code does import java.util.*; public class...

    Provide comments for this code explaining what each line of code does import java.util.*; public class Chpt8_Project {    public static void main(String[] args)       {        Scanner sc=new Scanner(System.in);        int [][]courses=new int [10][2];        for(int i=0;i<10;i++)        {            while(true)            {                System.out.print("Enter classes and graduation year for student "+(i+1)+":");                courses[i][0]=sc.nextInt();                courses[i][1]=sc.nextInt();                if(courses[i][0]>=1...

  • 5. Write a static method "f(n)" in the space provide, that returns O if n is...

    5. Write a static method "f(n)" in the space provide, that returns O if n is even, and if n is odd, returns 1 or -1 according as n is greater than or less than 0. importjava.util.Scanner; public class Q_05 Your "f(n)" method: public static void main(String args[]) mana int n; Scanner input = new Scanner(System.in); System.out.print("Please enetrn: "); n=input.nextInt(); System.out.println(f(n)); "Method f(n)" 7. Write a static method "max" in the space provide, that returns the maximum value from 3...

  • import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y,...

    import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...

  • 1. Import file ReadingData.zip into NetBeans. Also, please download the input.txt file and store it into...

    1. Import file ReadingData.zip into NetBeans. Also, please download the input.txt file and store it into an appropriate folder in your drive. a) Go through the codes then run the file and write the output with screenshot (please make sure that you change the location of the file) (20 points) b) Write additional Java code that will show the average of all numbers in input.txt file (10 points) import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.io.*; 1- * @author mdkabir...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...

  • Person Name: John Doe Person Birth Year: 1960 Person Name: Emily Zhang Person Birth Year: 2007...

    Person Name: John Doe Person Birth Year: 1960 Person Name: Emily Zhang Person Birth Year: 2007 Student Major: Finance Person Name: Paul zhang Person Birth Year: 1970 Instructor Salary: $50,000.00 Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) 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 PersonTest.main(PersonTest.java:47) import java.util.Scanner; public class PersonTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Person Name: "); String student_name = scan.nextLine(); System.out.print("Person Birth Year: "); int student_yearOfBirth = scan.nextInt(); Person p =...

  • *This needs comments for each line of code. Thanks in advance!* import java.util.Scanner; public class LabProgram...

    *This needs comments for each line of code. Thanks in advance!* import java.util.Scanner; public class LabProgram {     public static void main(String[] args) {         Scanner scnr = new Scanner(System.in);         int numCount = scnr.nextInt();         int[] Array = new int[numCount];                for(int i = 0; i < numCount; ++i) {             Array[i] = scnr.nextInt();         }         int jasc = Array[0], gws = Array[1], numbers, tempo;         if (jasc > gws) {             tempo = jasc;             jasc...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • Complete the do-while loop to output 0 to countLimit. Assume the user will only input a...

    Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }

  • read the code and comments, and fix the program by INSERTING the missing code in Java...

    read the code and comments, and fix the program by INSERTING the missing code in Java THank you please import java.util.Scanner; public class ExtractNames { // Extract (and print to standard output) the first and last names in "Last, First" (read from standard input). public static void main(String[] args) { // Set up a Scanner object for reading input from the user (keyboard). Scanner scan = new Scanner (System.in); // Read a full name from the user as "Last, First"....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT