473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Printing numbers along the side of a program

JavaStudent07
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 1278
^^^^^^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
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 Expert 1GB
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
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
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. ...
3
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...
4
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:...
4
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...
4
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...
4
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...
4
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...
0
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...
18
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
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,...

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.