473,785 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to print() colums

1 New Member
I'm grateful for any help here!

My program is generally quite a simple problem; must read in a list containing names and numbers and print it out like a phonebook in alphabetical order, in order of surname, comma, forename, and a number in a 2nd column. An example of the input is:

Fred Flintstone 555437
John Wayne 645373
Michael Schumacher 0343653
etc.

And the output should be:

Flintstone, Fred
555437
Michael, Schumacher
0343653
John, Wayne
645373

In my program I must create a class called person (strings of forename surname etc). I have an array of type Person (each array slot contains 3 strings [I use the number as a string]).

Everything works perfectly. The only problem is the printing part. As normal I'm printing the array with a for loop, concatenating the elements in the desired order, eg

static void printPerson(Per son[] bk, int length)
{
for (int y = 0; y < length; y++)
{
String num = bk[y].number;
System.out.prin tln(bk[y].surname + ", " + bk[y].forename + ('\t') + ('\t') + bk[y].number);
}
}


Of course what happens here is that when a name is above a certain length, the number will tab over even further. So it's not a solution. I was recommended to look at using printf(), but not getting the result with it. So anybody have any idea (...quite likely a simple answer!)
Mar 30 '07 #1
1 1730
horace1
1,510 Recognized Expert Top Contributor
use system.out.prin tf
http://java.sun.com/developer/technicalArticl es/Programming/sprintf/

e.g.
Expand|Select|Wrap|Line Numbers
  1.     String s1="Fred Flintstone";
  2.     int i1=555437;
  3.     String s2="John Wayne";
  4.     int i2= 645373;
  5.     String s3="Michael Schumacher";
  6.     int i3= 0343653;
  7.     System.out.printf("%25s %10d\n", s1, i1);
  8.     System.out.printf("%25s %10d\n", s2, i2);
  9.     System.out.printf("%25s %10d\n", s3, i3);
  10.  
would print
Expand|Select|Wrap|Line Numbers
  1.           Fred Flintstone     555437
  2.                John Wayne     645373
  3.        Michael Schumacher     116651
Mar 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1474
by: Ajay Garg | last post by:
What is the way we could implement a business logic from a Table by storing it statemnnets in a colums and defining an execute sql to execute it.Some legal requirements make it diffcult for us to create modify stored procdures so Iwant to have a process where we create new rows in a table and execute it to execute business logic. All views are welcome. Havin g one table two tables different approaches to store ststements
5
8104
by: Joy | last post by:
Hi guys, I am in a tricky situation, I really really hope someone will help me. I got a layout with a main container and three colums inside. Main container: 100% height; 90% width; float: left First colum: 100% height; 200px width; float: left Second colum: 100% height; 200px width; float: right Third colum: 100% height And here I stop, because nothing seems to work in order to set correctly
0
1267
by: Erik | last post by:
Hi, I want to make an effect like in excel when you fix colums and then you can scroll the rest colums behind the fixed. But I won't or can't do this with frames, so has anybody seen a website or an example with this effect. Maybe dhtml or even with css or something else like that. Thank you very much
0
1471
by: Bernard Dhooghe | last post by:
In http://www-1.ibm.com/partnerworld/pwhome.nsf/weblook/eac_a_webcast_052504.html the writer says (page 50, Multidimensional Clustering Advisor): " The MDC Advisor feature of the DB2 Design Advisor recommends MDC clustering dimensions, including coarsification on base colums in order to improve workload performance
3
1940
by: Y. Gauthier | last post by:
Hi, I made a report with Access 2000 I show records, plus a total of some colums. I first had: totalC = col1 + col2 + col3 + col4 Then I changed it to: totalC = col1 + col2
1
1265
by: basulasz | last post by:
May be it is a bit easy question but i don't know the way to display data in bounded colums. I get data from DB with a datareader, and I want to display them on bounded colums. I dont want to create colums dynamically. How can I do that? -- No Sign
1
9918
by: Eduardo78 | last post by:
I am having trouble printing in landscape, when i print directly from the grid. This is how my code looks rightnow: Private Sub cmdPrintFromGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrintFromGrid.Click Dim prtDoc As New Printing.PrintDocument()
1
3769
by: hgm_kh | last post by:
My MS-Access application was working perfectly under WIN95/98. When I converted the MS-Access application to run on WIN-XP, some reports which have $-value colums, do no longer print as shown in print preview. Actually, the columns do print, but all values are just blank. When I used a friend's PC (WIN-XP), that same report printed just fine. I wonder if there is a parameter within my WIN-XP that is the cause of my problem. Any suggestions would...
0
1602
by: zafar | last post by:
I don't know what property should be used for hiding colums in Data Grid, whereas in Data Grid View we have DataGridView1.Colums(index).Visible = False , But how can I hide Colums in Data Grid.. Secondly Can I make multiple bands in Data Grid View, mean parent and child table appearance in Data Grid View, If so then how.. because when I pass a DataSet (which have relationships between the table in it) to data grid view it only shows the...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.