Java Java Basics Perfecting the Prototype Reviewing Our Feedback

help with this program guys please

help me guys, and find out what is wrong of my programimport java.io.Console; public class Tree{ public static void main(String [] args){ Console console=System.console(); String firstName=console.readLine("what is your name "); String middleName=console.readLine(" what is your middle name? "); String lastName=console.readLine("what is your last name? "); String ageLast=console.readLine("how old are you "); int age=4; if(age<3){ console.printf("yes is the right age"); System.exit(0); }

}

3 Answers

Hi please format your code properly so that we are able to help you effectively. Happy coding!!! Here is how to format your code: https://teamtreehouse.com/community/posting-code-to-the-forum

Mark Casavantes
PRO
Mark Casavantes
Pro Student 13,401 Points

Good Afternoon Ayub,

I am not sure if I changed this code too much. I am not sure what your assignment was. I hope what I wrote here is helpful. Feel free to ask more questions.

package com.teamtreehouse;

import java.io.*; 
import java.util.*;

public class Tree
{ 
    public static void main(String[] args) 
    { 
        Console console=System.console();
        Scanner sc = new Scanner(System.in);

        System.out.println("What is your name? "); // I put in print statements instead of including them inside your ().
        String firstName=sc.nextLine(); 

        System.out.println("What is your middle name? ");       
        String middleName=sc.nextLine(); 

        System.out.println("What is your last name? ");     
        String lastName=sc.nextLine(); 

        System.out.println("How old are you? ");        
        int ageLast=sc.nextInt(); // I changed age to ageLast.

        sc.close();

        // int age=4; (I don't know if this should be ageLast as well.

        if(ageLast<3)
        { 
            console.printf("yes is the right age."); 
            System.exit(0); 
        }
    }
}
import java.io.Console; 

public class Tree{
    public static void main(String [] args){ 
        Console console=System.console(); 
        String firstName=console.readLine("what is your name "); 
        String middleName=console.readLine(" what is your middle name? "); 
        String lastName=console.readLine("what is your last name? "); 
        String ageLast=console.readLine("how old are you "); 
        int age=4; 
            if(age<3){ 
                console.printf("yes is the right age"); 
                System.exit(0); }

}

You are missing } from the end to close main class.

Also since you set age to 4 and since 4 is bigger than 3 your program ends right there and console doesn't print anything out

        int age=4; 
            if(age<3)

Check the next lesson how to do user input age restriction :)