473,671 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing numbers along the side of a program

JavaStudent07
64 New Member
Expand|Select|Wrap|Line Numbers
  1. File file=new File("H:/Numbers.java");
  2. String Text="";
  3. int intNumber=1;
  4. BufferedReader lineIn=new BufferedReader(new FileReader(file));
  5.  
  6. try
  7. {
  8. Text=lineIn.readLine();
  9. }
  10.  
  11. catch(FileNotFoundException e)
  12. {
  13. System.out.println("The file you entered was not found.");
  14. System.exit(0);
  15. }
  16.  
  17. try
  18. {
  19. Text=lineIn.readLine();
  20. }
  21.  
  22. catch(IOException b)
  23. {
  24. System.out.println("ERROR! Please try again.");
  25. }
  26.  
  27. while(linetext!=null)
  28. {
  29. System.out.print(intNumber+" "+Text);
  30. intNumber=(intNumber+1);
  31. System.out.print("\n");
  32.  
  33. try
  34. {
  35. Text=lineIn.readLine();
  36. }
  37.  
  38. catch(IOException d)
  39. {
  40. System.out.println("ERROR! please try again.");
  41. }
  42. }
  43. }
Jan 26 '07 #1
4 1291
JavaStudent07
64 New Member
^^^^^^look up for code^^^^^^^^^^^
if anyone knows a more efficient way of printing numbers along the side of a program, please let me know
(for a print out the teacher is looking for;
1 public class main Blah
2 etc.
Jan 26 '07 #2
JavaStudent07
64 New Member
this is not high priority, if you dont feel like helping dont bother because it works, i'm just looking for a more efficient method that i can do quick in case i need to use this program in the future
Jan 26 '07 #3
horace1
1,510 Recognized Expert Top Contributor
this is not high priority, if you dont feel like helping dont bother because it works, i'm just looking for a more efficient method that i can do quick in case i need to use this program in the future
you could simplify the code a bit, e.g.
Expand|Select|Wrap|Line Numbers
  1.   try
  2.     {
  3.     File file=new File("Numbers.java");
  4.     BufferedReader lineIn=new BufferedReader(new FileReader(file));
  5.     int intNumber=1;
  6.     String linetext;
  7.     while((linetext=lineIn.readLine())!=null)
  8.        System.out.println((intNumber++)+" "+linetext);
  9.     }
  10.   catch(FileNotFoundException e)
  11.    {
  12.     System.out.println("The file you entered was not found.");
  13.     System.exit(0);
  14.    }
  15.  catch(IOException d)
  16.   {
  17.    System.out.println("ERROR! please try again.");
  18.   }
  19. }
  20.  
Jan 26 '07 #4
JavaStudent07
64 New Member
SWEET :) thats all i needed, helped A LOT :) Eupert and Roper give two thumbs up!
Jan 29 '07 #5

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

Similar topics

10
24886
by: Brian Hanson | last post by:
Hi, I am trying to programmatically print a pdf file via an asp.net application. I have seen other postings that mention the following code used or something similar to it in a vb.net app. Process.Start("C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe", "/p /h ""C:\Program Files\Adobe\Acrobat 5.0\Help\ENU\ACROBAT.PDF""")
3
705
by: RBisch | last post by:
I am finding that some of the properties off of the PrinterSettings object are misleading For example, When I test the CanDuplex on a printer I know duplexes, the property is false. Another one is DefaultPrinter, it is set to false when I know that I have that printer set as default (I verify via the "Printers and Fax" applet Can anyone confirm or explain TIA
4
1813
by: Sam Kong | last post by:
Hello! I wonder if there's a good way to make a function that calculates 2 big numbers (whole numbers) expressed as strings and return a result string with the value of a number? For example: string MyAdd(string s1, string s2); s = MyAdd("10", "20"); //=> returns "30"
4
2185
by: Russ | last post by:
To ASP.NET printing experts: My Asp.net web form needs to print some reports at the client side. I've been trying to research this and find some confusing and conflicting information in previous news group answers. Some say "Crystal Reports", others say "PDF" or "Word", and others say that you cannot do this at all on client side??? My reports are text documents that are already formatted, contain form feeds, and positioning controls...
4
1895
by: Al Jones | last post by:
Well, hopefully that title get someones attention. In this old gwbasic program I've converted I *have* sucessuflly converted it to print to a file and the output is acceptable. From there I have printPreview and (what is it) PrinDocument working. All of the references I've found (to include several books) show that method of printing ... my question - is it not possible to print the document 'on the fly' to allow proper paging, page...
4
1541
by: MLM450 | last post by:
I have an unmanaged C++ program that displays a printer dialog and then asks my C# program to perform the printing operation. What printer info do I pass to my C# program? It looks like I need to establish values in the PrinterSettings property of a PrintDocument object. But how? I think I should be able to use the print DC, but I don't see a way
4
5894
by: Lucas Ponzo | last post by:
Hi All, I have an ASP.NET 2.0 app. The users access the pages, uniquely via pocket pc ... I need to print a page. But I need that the page print on a printer installed on the web server hosting my application. Step 1) The user clicks the Print icon in the web page
0
1824
by: hugo | last post by:
I need urgent help with this program: Using C, write a calendar progam so that the user provides only a year. The program should print a calendar for the given year to the file calendar.dat. The first line of output should be the year. Print two months side by side so that the calendar will fit on one 8 1/2 x 11 inch page. I have problems using FILES, and printing the months side by side.
18
11290
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing classes, for each of the checked rows in the GridView. This works fine in the Visual Studio 2005 development environment on localhost. But, when I move the page to the web server, I get the error "Settings to access printer...
0
8909
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8596
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
8667
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
7428
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
4399
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2806
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
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1801
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.