Jump to content
  • Advertisement
Sign in to follow this  
dave_lu

another noobish Java Question!

This topic is 4811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
like how in microsoft words when you want to center titles or whatever you go up and press the Center button...or in html(center)
like in the middle of the output console on ReadyToProgram

Share this post


Link to post
Share on other sites
He means where are you displaying the text. Any specific control, drawing it on a canvas, just console output?

shmoove

Share this post


Link to post
Share on other sites
The console is 80 chars wide, so you would have to add (80-[length of string])/2 spaces to the beginning of the string you print.

shmoove

Share this post


Link to post
Share on other sites
public static void printCenter(String str)
{
int numSpaces = (80 - str.length()) / 2;
for(int i = 0; i < numSpaces; ++i)
System.out.print(" ");
System.out.println(str);
}

Share this post


Link to post
Share on other sites
And Thank you trevaaar!

I have another question to ask you guys


how could i fit more than one var in

BufferedReader (var) = new BufferedReader(new InputStreamReader(system.in));

Share this post


Link to post
Share on other sites
Quote:
Original post by dave_lu
how could i fit more than one var in

BufferedReader (var) = new BufferedReader(new InputStreamReader(system.in));


I don't know what you mean by "fit more than one var in". What is being done here is that you create an object of type BufferedReader (by the way, drop the brackets around 'var'; they do nothing and will confuse basically anyone who reads your code); the BufferedReader is then used to read data from the System.in (pay attention to capitalization!) into other variables.

If you want more than one BufferedReader, just make another one in the same way - but it probably won't do you any good to have more than one BufferedReader, at least not for the same data source (System.in). If you're trying to read several values, then you need to make variables to hold each value, and use the BufferedReader's methods in order to read into them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!