Re: Real Newbie Question
From: Anthony Borla (ajborla_at_bigpond.com)
Date: 12/21/03
- Previous message: Anthony Borla: "Re: Numeric overflow"
- In reply to: Rob: "Real Newbie Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 21 Dec 2003 11:28:55 GMT
"Rob" <talon2lm@yahoo.com> wrote in message
news:c5ydnUUXgYNsg3iiRVn-sQ@comcast.com...
>
> Just started Java...This is for my first program.
>
> What's the easiest way to center text? Not on an applet, just
> from command prompt.
>
Create a 'String' that is centred within a fixed-width area [e.g. a line
assumed to be 80 characters in length] by being padded with space [or other
suitable] characters on either side.
Some code just to get you started:
public class MyFirstProgram
{
public static void main(String[] args)
{
String centredLine =
centreText(80, "A CENTRE TITLE", ' ');
System.out.println(centredLine);
}
public static String centreText(int lineLength, String text, char
padCharacter)
{
// Fill with code ...
}
}
I hope this helps.
Anthony Borla
- Previous message: Anthony Borla: "Re: Numeric overflow"
- In reply to: Rob: "Real Newbie Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|