Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help with system.out.print
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Banished_Outlaw




PostPosted: Sat Jan 19, 2008 4:34 pm   Post subject: help with system.out.print

One of the tedious things in Java is that every time i need to print strings, I need to write system.out.print. Is there any way i can type a whole paragraph by using
system.out.print only once? Is there some command like system.out.printpr (paragraph) to do this? Any help would be appreciated. Thanks Smile
Sponsor
Sponsor
Sponsor
sponsor
StealthArcher




PostPosted: Sat Jan 19, 2008 4:55 pm   Post subject: RE:help with system.out.print

system.out.print"\tsentences\n\tsentences\n\tsentences"
Banished_Outlaw




PostPosted: Sat Jan 19, 2008 5:07 pm   Post subject: Re: help with system.out.print

the /t (tab) and /n (newline) works perfectly but is there any way i can continue the command in the next line without ending it because if i do this:

System.out.print("sentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\");
The command will strech on forever which is bad programming syntax since i need to add comments to my programs to?

Is there any way i can do this:

System.out.print("sentences\nsentences\nsentences\nsentences\nsentences\nsentences\n ...
sentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\n ...
sentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\n ...
sentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\n ...
sentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\nsentences\n); ?
richcash




PostPosted: Sat Jan 19, 2008 5:27 pm   Post subject: Re: help with system.out.print

code:
System.out.print("part1" +
   "part2" +
   "part3")

The + sign acts as the concatenation operator in java (meaning it combines two strings into one).
HeavenAgain




PostPosted: Sat Jan 19, 2008 6:13 pm   Post subject: RE:help with system.out.print

if you going to do that.... why not just put them on a .txt file and just read from it, then print
and also in Java1.6 you could import static class, which means you can import System.out.print(ln) and just go like
code:
println("hello world");

saves you the typing for System.out.
ericfourfour




PostPosted: Sat Jan 19, 2008 7:03 pm   Post subject: RE:help with system.out.print

The first thing HeavenAgain suggested is the best way to do this. One at a time, read each line and print it. This allows you to format the text the way you want in the text file. Just make a method that does this so all you have to do is call the method with the file name.
Banished_Outlaw




PostPosted: Sat Jan 19, 2008 8:34 pm   Post subject: Re: help with system.out.print

that sounds good, but ill have to learn to import text classes in java and i dont have much time, i think ill just follow a combination of richcash's and StealthArcher's solutions since im a very lazy person Rolling Eyes , but after im done this project, i'll definitely try learning the implementation of text files in java. but thanks a lot, you guys are really helpful Very Happy
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: