|
| ||||||||||
| Tags: how to, java, tabular format |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How to get a Java Program output in Tabular format
I am coded the program in such a way that the system asks the user to input two numbers, then calculates two number with addition and subtraction and then prints out the output with the following section. Code: Operation Result 10+10 20 10-10 0 |
|
#2
| |||
| |||
| Re: How to get a Java Program output in Tabular format
If you have been able to code the entire program successfully then I don’t think you should face any problem while preparing the format and coding for the resulting output. Obviously if you try to simply print the result of the entered input numbers and the operations performed on them then you might get a messy output where all the numbers would be sticking each other as if there is no space on the screen and also the output would not be understandable. The best you can try out is the use of Escape sequence for arranging the output in a proper arranged fashion. Make use of \t (tab escape sequence) which might help you in separating and maintaining the distance between the “operation” and “Result” column. |
|
#3
| |||
| |||
| Re: How to get a Java Program output in Tabular format
Even I think making the use of escape characters in such cases is very much recommended. I guess not just tab escape character but you will also have to make use of \n i.e. new line for creating the above format. I mostly take help of the escape sequences to create such tabular format of output. Anyways I will help you with various types of escape sequence along with their description.
|
|
#4
| |||
| |||
| Re: How to get a Java Program output in Tabular format
After playing a lot around the code I found the following trick. I would request you to first look at the following code: Code: System.out.printf("%s \t \t %s\n", "Operation", "Result");
String format = "%-28s %-7d \n";
String operators = Integer.toString(num1) + "+" + Integer.toString(num2);
System.out.printf(format, operators, total);
|
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to get a Java Program output in Tabular format" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to convert the Nero 11 & patent activation fax output to e-mail format | Iraqat | Windows Software | 1 | 08-03-2012 02:29 AM |
| how to increase the number of decimal digits in JAVA program output? | Dennis Racket | Software Development | 2 | 19-01-2012 01:38 PM |
| How to ASP.NET data will be output directly into Excel format | Savannah87 | Software Development | 4 | 12-02-2010 03:58 AM |
| C program is unable to give correct output | Ujagar | Software Development | 4 | 29-01-2010 07:45 PM |
| Link List Example in Java Sample program in Java | trickson | Software Development | 2 | 04-08-2009 08:23 PM |