Easy question (print location)
Hi all I have forgotten, how to print chars in a certain location.
For exaple: I have
a=1;
b=12;
c=123;
and I need several columns with certain distance:
column:
1
12
123
Hi all I have forgotten, how to print chars in a certain location.
For exaple: I have
a=1;
b=12;
c=123;
and I need several columns with certain distance:
column:
1
12
123
> Hi all I have forgotten, how to print chars in a
> certain location.
>
Yeah, I hate it when that happens.
So, what have you tried? You got any code?
> Hi all I have forgotten, how to print chars in a
> certain location.
>
> For exaple: I have
>
> > a=1;
> b=12;
> c=123;
>
>
> and I need several columns with certain distance:
>
> column:
> 1
> 12
> 123
I have no idea where would you like to print it.
Are you trying to print at the console then use println(). ^_^
I have something like this:
String name1="Jim Carry"
String name2="Marry Poppins"
String name3="Bill Murray"
String association1="lol";
String association2="goodbye";
String association3="groundhog day"
System.out println(" NAMEASSOCIATION");
//table here
For example, I have string 8, 12,7 characters long and I want them all take 15. So second column starts at 16.
It's easy enough to make a little left or right padding method for your output. Why not try to create one?
> there was a method to do it... or I just mix something
hmmmmm, I don't remember one in particular, but I could be wrong. I know that in the past, I've created a little method, just a few lines of code.
Just as you ordered ... here is the code...
apply it and see the results..
public class Test {
public Test() {
}
public static void main(String args[]){
String name1="Jim Carry";
String name2="Marry Poppins";
String name3="Bill Murray";
String association1="lol";
String association2="goodbye";
String association3="groundhog day";
System.out.println("NAMEASSOCIATION");
System.out.println("");
columnFixer(name1,15,association1);
columnFixer(name2,15,association2);
columnFixer(name3,15,association3);
}
public static void columnFixer(String name,int columnWidth,String association){
System.out.print(name);
//the number 4 is for the space that NAME word is taking
int spacesLeft = columnWidth + 4 - name.length();
for (int i = 0; i < spacesLeft; i++) {
System.out.print(" ");
}
System.out.print(association);
System.out.println();
}
}
and the output would be like this:
NAMEASSOCIATION
Jim Carry lol
Marry Poppinsgoodbye
Bill Murraygroundhog day