I'm trying to right justify my integers but it isn't working
-
I have four simple computations in my program. All integer results. I want the output to be right justified but it ain't looking that way. Right now the 5 underneath the 30 looks like it's being placed between the 3 and the 0 (in the above number 30). The -10 looks like it is being correctly right justified. The -10 looks like it is being correctly right justified with the 30. And the 200 takes up the maximum field width of 3 which I have set. My output has a ragged right appearance so I don't know where I'm going wrong. My code looks like this:
public class FormattingOutput
{
public static void main(String args[])
{int a, b, c, d; a = 10 + 20; b = 10 - 5; c = 10 - 20; d = 10 \* 20; System.out.printf("%3d%n", a); System.out.printf("%3d%n", b); System.out.printf("%3d%n", c); System.out.printf("%3d", d); }
}
-
I have four simple computations in my program. All integer results. I want the output to be right justified but it ain't looking that way. Right now the 5 underneath the 30 looks like it's being placed between the 3 and the 0 (in the above number 30). The -10 looks like it is being correctly right justified. The -10 looks like it is being correctly right justified with the 30. And the 200 takes up the maximum field width of 3 which I have set. My output has a ragged right appearance so I don't know where I'm going wrong. My code looks like this:
public class FormattingOutput
{
public static void main(String args[])
{int a, b, c, d; a = 10 + 20; b = 10 - 5; c = 10 - 20; d = 10 \* 20; System.out.printf("%3d%n", a); System.out.printf("%3d%n", b); System.out.printf("%3d%n", c); System.out.printf("%3d", d); }
}
I know now. You have to use a fixed width font in your console. I wasn't.
-
I have four simple computations in my program. All integer results. I want the output to be right justified but it ain't looking that way. Right now the 5 underneath the 30 looks like it's being placed between the 3 and the 0 (in the above number 30). The -10 looks like it is being correctly right justified. The -10 looks like it is being correctly right justified with the 30. And the 200 takes up the maximum field width of 3 which I have set. My output has a ragged right appearance so I don't know where I'm going wrong. My code looks like this:
public class FormattingOutput
{
public static void main(String args[])
{int a, b, c, d; a = 10 + 20; b = 10 - 5; c = 10 - 20; d = 10 \* 20; System.out.printf("%3d%n", a); System.out.printf("%3d%n", b); System.out.printf("%3d%n", c); System.out.printf("%3d", d); }
}
Your output sentence is wrong.This is JAVA ,is not C.