The Artima Developer Community
Sponsored Link

Java Answers Forum
help with the display when printed

1 reply on 1 page. Most recent reply: Nov 13, 2002 9:15 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
ben

Posts: 57
Nickname: loftty
Registered: Oct, 2002

help with the display when printed Posted: Nov 13, 2002 7:43 AM
Reply to this message Reply
Advertisement
hello i am having trouble with the output of my file what is happening when i compile this it will print it out like so ben
hugh
matt
peter
jason
lunt

and the way i want it to be printed out is like this
ben hugh
matt peter
jason lunt
is there any way i can do this i have used the \t but it still prints out in the first example
my code is below to show you how im doing it any suggestions on doing it another way i would be most grateful
thanks ben
Enumeration e = v.elements();
Object o;
for(int i = 0;e.hasMoreElements();i++) {
o = e.nextElement();
if (i%10 == 1){
System.out.println(o.toString());
}

else if (i%10 == 1){
System.out.println("\t"+o.toString());
}


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: help with the display when printed Posted: Nov 13, 2002 9:15 AM
Reply to this message Reply
import java.util.*;
 
public class Test{
	
	public static void main(String[] args){
		Test test = new Test();
		test.test();
		System.exit(0);
	}
	
	public void test(){
		Vector v = new Vector();
		v.add("ben");
		v.add("hugh");
		v.add("matt");
		v.add("peter");
		v.add("jason");
		v.add("lunt ");
		Enumeration e = v.elements();
		Object o;
		for (int i = 0; e.hasMoreElements(); i++) {
			if (i%2 == 0) System.out.print((String)e.nextElement());
			if (i%2 == 1) System.out.println(" " + (String)e.nextElement());
		} 	
	}	
}

Flat View: This topic has 1 reply on 1 page
Topic: Need one-2one ON line tutorial. willing to pay ?50.00 for each task Previous Topic   Next Topic Topic: illegal start of expresion

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use