Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
PLUS
Mark Casavantes
Courses Plus 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 :)