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 Getting Started with Java Introduction to Your Tools

My Output did not display

import java.io.Console;

public class Introductions {

public static void main(String[] args) {
    Console console = System.console();
    // Welcome to the Introductions program!  Your code goes below here
    console.printf("Hello, my name is Wan");

} }

I write the code as instructed from the video, but when i compile the text, the text did not display

treehouse:~/workspace$ javac Introductions.java
treehouse:~/workspace$ ls
Introductions.class Introductions.java
treehouse:~/workspace$ java Introductions treehouse:~/workspace$

What i did wrong?, i am confuse.The "Hello, my name is Wan" didn't display

5 Answers

I'm glad you got it to work. :) Btw if my answers were helpful to you, if you wouldn't mind marking one as 'best answer' that would be highly appreciated. Also, you were close with your conditional statements, your only syntax error was after your boolean expressions, in your if statements. Remove the semi-colons after the if portion in your in your if - else statements.

import java.io.Console;

public class Introductions {

    public static void main(String[] args) {
        Console console = System.console();

        String myName = console.readLine("what is your name ?");
        if (myName.equals("Dog")) //you had a  semi-colon here
        {
          console.printf("Go to hell\n");
          System.exit(0);  
        }

        String age = console.readLine("How old are you btw?");
        int old = Integer.parseInt(age);

        if (old<13) //you also had a semi-colon here
        {
          console.printf("Dude get lost,you are under age\n");
          System.exit(0);
        }

        // Welcome to the Introductions program!  Your code goes below here
        console.printf("hi %s nice to meet you im window\n",myName);  
        console.printf("Finally %s you finally get the compiler working\n",myName);
        console.printf("Good for you %s \n",myName);
  }
}

Ty bro u are awesome :D

No problem. :) Let me know if you have any other questions.

sorry to bother you again bro but i need your help

https://w.trhou.se/zmi3jra31s

my do while keep repeating my text without giving me the chance to re input it back, why?

Watch out for infinite loops. You created two by assigning the readLine method to your name string variable and old string variable outside of your 'do code-block'. Let me know if you want me to clarify about how, assigning the readLine method to your string variables, outside of your 'do code-block', creates an infinite loop.

All you need to do is assign your string variables, name and old, inside of your 'do code-block' as the first line of code, so if your boolean-expressions from the if-statements as well as the 'while boolean-expression' come back as true it will always invoke the readLine method first.

I refactored your code just a little bit, but it seems to work as expected.

import java.io.Console;

public class Introductions {
    public static String name;
    public static String old;
    public static int age;
    static Console console = System.console();

    public static void main(String[] args) {
       // Welcome to the Introductions program!  Your code goes below here

     do{
        name = console.readLine("\n What is your name?  "); //This must be assigned inside of your 'do code-block' as the first line of code.
        if(name.equalsIgnoreCase("piggy")||
           name.equalsIgnoreCase("Dog")  ||
           name.equalsIgnoreCase("Shit") ||
           name.equalsIgnoreCase("Dick"))
        {
          console.printf("Hey that's not nice! Please try again.");
        }

       }while(name.equalsIgnoreCase("piggy")||
           name.equalsIgnoreCase("Dog")  ||
           name.equalsIgnoreCase("Shit") ||
           name.equalsIgnoreCase("Dick"));


     do{  
        old = console.readLine("\n How old are you?  "); //This must be assigned inside of your 'do code-block' as the first line of code.
        age = Integer.parseInt(old);
        if(age < 18)
        {
         console.printf("I'm sorry, you are not old enough. Please Try Again.");
        }

       }while(age < 18);

      console.printf("Hello %s and welcome to java,cant wait to see your 1st app\n",name);
  }
}

Your code looks fine to me, I opened a workspace and it worked perfectly. Maybe try compiling and running it on one line:

javac Introductions.java && java Introductions

ty for your reply, i try your method but still not working..maybe its the workspace prob..im using it in chrome

Make sure you java file name is with a capital "I". And when you compile and run make sure you use a Capital "I"

I'm using chrome as well, try copy/paste my code and see if it works:

import java.io.Console;
public class Introductions {

public static void main(String[] args) {
    Console console = System.console();
    // Welcome to the Introductions program!  Your code goes below here
    console.printf("Hello, my name is Wan %n");
  }
}

And compile and run on one line like before.

i did what you ask and still the same result, i think it the compiler problem, cause my coding is correct, i appreciate your help Derek Markman

I don't think its the compilers fault seeing as how I just opened a new one up and compiled/ran my code fine, is your java file name with a capital "i"? Or a lowercase? Your java file name Introductions.java need a capital "i". Also make sure that your class name in your actual code is spelled with a capital "i".

If you used my code, I used a %n new line in my print statement, this is what your console should look like if compiled and ran properly:

treehouse:~/workspace$ javac Introductions.java                                                  
treehouse:~/workspace$ java Introductions                                                        
Hello, my name is Wan                                                                            
treehouse:~/workspace$

Also, after you compiled you should've got a .class file auto generated, did you get an Introductions.class file? Take a snapshot of your workspace (It's the top-right corner inside your workspace, it's a square with a dot in the middle icon) After you snapshot your workspace send me the link to it.

now u mention it Derek, i check there is no Introduction.class file, when i click it, it says "No preview available"

btw this the snapshot link https://w.trhou.se/pafdct8rwq

On your snapshot I can see that you did get an Introductions.class file. Which means that your code compiled successfully. What I want you to do is delete the class file, and the test java file and then just re compile your code:

javac Introductions.java

after you compile, take another snapshot and let me see it. And you shouldn't be able to preview your class file, there is no need to anyways so don't worry that's normal.

ty Derek its working now,i have another question i want to ask you,

https://w.trhou.se/0l1ef1mdow this is the link

its about the if statement, in the if statement those lower than 13 will get a text that i provide,and exit the program but if input more it will resume the system, my problem is when i input higher the 13 it will still get that text..why?

sorry for my bad english