Results 1 to 7 of 7
Thread: aligning numbers,..
- 10-08-2008, 04:09 PM #1
Member
- Join Date
- Oct 2008
- Location
- Philippines
- Posts
- 8
- Rep Power
- 0
aligning numbers,..
pls help me in aligning numbers,.. this is my code,.. the numbers must be align,. thnx in advance guys!
public class Table{
public static void main(String args[]){
try{
for(int l=0;l<10;l++){
System.out.print(" "+l );
}
System.out.println();
for(int y=1;y>-10;y--){
System.out.print(" "+y );
}
System.out.println();
for(int m=2;m>-9;m--){
System.out.print(" "+m);
}
System.out.println();
for(int a=3;a>-8;a--){
System.out.print(" "+a);
}
System.out.println();
for(int r=4;r>-7;r--){
System.out.print(" "+r);
}
System.out.println();
for(int i=5;i>-6;i--){
System.out.print(" "+i );
}
System.out.println();
for(int x=6;x>-5;x--){
System.out.print(" "+x );
}
System.out.println();
for(int z=7;z>-4;z--){
System.out.print(" "+z );
}
System.out.println();
for(int q=8;q>-3;q--){
System.out.print(" "+q );
}
System.out.println();
for(int w=9;w>-2;w--){
System.out.print(" "+w );
}
}catch(Exception e){}
}
}
- 10-08-2008, 05:29 PM #2
Senior Member
- Join Date
- Aug 2008
- Location
- Stockholm, Sweden
- Posts
- 119
- Rep Power
- 0
What on Earth are you talking about? Aligned? Aligned to what? Where? Who? What output are you getting and what do you expect?
- 10-08-2008, 06:00 PM #3
Are you talking about the println output? Do you want the output to be right adjusted with leading blanks?
Decide on the longest number of digits(MaxDig) you are going to output.
Convert the int to String.
Pad the String on the left with blanks so that it has MaxDig total length.
- 10-09-2008, 05:42 AM #4
Member
- Join Date
- Oct 2008
- Location
- Philippines
- Posts
- 8
- Rep Power
- 0
the output numbers must be aligned to the other one below like a multiplication table,.. but this is a subtraction table,.
-
You might want to read up on using System.out.printf(...) It will do what you want here.
- 10-09-2008, 05:53 AM #6
Member
- Join Date
- Oct 2008
- Location
- Philippines
- Posts
- 8
- Rep Power
- 0
norm, can you show me the syntax to set maxdig? because i'm new to java
- 10-09-2008, 01:59 PM #7
Similar Threads
-
Counting numbers up and down
By radio in forum New To JavaReplies: 4Last Post: 05-06-2011, 03:03 PM -
problem aligning both image/text inside a button
By rick_cols in forum SWT / JFaceReplies: 0Last Post: 09-18-2008, 08:20 PM -
Having Trouble Aligning JLabels
By Mark_Petrov in forum AWT / SwingReplies: 0Last Post: 01-20-2008, 05:22 PM -
Aligning Labels
By Java Tip in forum Java TipReplies: 0Last Post: 01-02-2008, 06:26 PM -
random numbers
By carlos123 in forum New To JavaReplies: 1Last Post: 12-22-2007, 02:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks