PDA

View Full Version : Beginner Java Question



tdrusk
June 10th, 2008, 01:47 AM
I have to use the /t to format my text. Hypothetically, I wrote

/* File Name: HelloWorld.java
*
* Purpose: Greeting the World.
*
* Name: your name goes here
*
*/
public class HelloWorld
{
// display the message hello World... on the screen
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}


How do I add /t to format the text?
}

NormR2
June 10th, 2008, 01:54 AM
Not sure what you mean by /t. Do you mean \t (the tab char)?
The \ is called the escape character and has special usage. It tells the compiler to handle the char following the \ in a special way. For a following t it requests a tab char, for an n a newline char, for " to treat it as an ordinary char and not String delimiter, etc

How do you want to "format" your text? The println() method writes to stdout. Add a \t to the String your writing with println() and observe the output.

tdrusk
June 10th, 2008, 01:57 AM
Not sure what you mean by /t. Do you mean \t (the tab char)?
The \ is called the escape character and has special usage. It tells the compiler to handle the char following the \ in a special way. For a following t it requests a tab char, for an n a newline char, for " to treat it as an ordinary char and not String delimiter, etc

How do you want to "format" your text? The println() method writes to stdout. Add a \t to the String your writing with println() and observe the output.
I'm sorry. I meant \t. That was my original problem.
I didn't think it would be as simple as just adding it in the "\tHello World!"
Is that proper?

NormR2
June 10th, 2008, 01:59 AM
Depends what you want the output to look like. Try it and see if its what you want.

tdrusk
June 10th, 2008, 02:37 AM
Depends what you want the output to look like. Try it and see if its what you want.
Looks fine to me. Thanks for your help guys.