Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: School Lab Work

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default School Lab Work

    import java.io.*;
    public class C13e1
    {
     
    	public static void main(String[] args) throws IOException
    	{
    		PrintWriter outFile = new PrintWriter(C13e1.txt);
    		for (int myNumber = 5; myNumber <= 100; myNumber + 5);
    		{
    			outFile.println(myNumber);
    		}
    			outFile.close();
    			System.out.println("File" +outFile + "successfully created.");
    			System.out.println();
    			System.out.println("End of Program.");
     
    	}
     
    }

    The code for these Laboratory exercises require you to build each program from scratch. No code exists on your jump drive for these programs. The output these programs generate and send to the Console window must match what is shown in the Console Output document – this includes the wording of messages and the line spacing between printed items.

    #1 – Name it C13e1 // Chapter 13 Exercise 1 – Writing to a Text File

    This program writes a series of integer numbers to a file named C13e1.txt and contains only one method – the required main method. The main method throws IOException. You must import java.io.* into your program.

    Within the main method, do the following:
    - Declare a PrintWriter object named outFile that points to the C13e1.txt file.
    - Set up a for loop where the startup action is int myNumber = 5; the true/false expression is myNumber <= 100; and the update action is myNumber + 5. Within the for loop, do the following:
    - Write to the C13e1.txt file using outFile.println(myNumber).
    - After the for loop, do the following:
    - Close outFile.
    - Display the entire “successfully created” message to the Console window.
    - Display a blank line and the End of Program message in the Console window.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: School Lab Work

    What's the question? Describe what you want help with; be specific.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: School Lab Work

    My main question is within my for loop it is giving me a problem with my myNumber variable when I am calling it within the outFile.println so I am confused with that.

Similar Threads

  1. Replies: 1
    Last Post: September 9th, 2013, 11:26 AM
  2. Need Help with While Loop Lab
    By LennDawg in forum Other Programming Languages
    Replies: 4
    Last Post: June 29th, 2012, 10:41 AM
  3. Help with a lab!
    By Spicy McHaggis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 2nd, 2012, 08:03 AM
  4. PLEASE HELP ME WITH MY COLLEGE LAB!
    By crsoccerplayer6 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 29th, 2011, 04:06 PM
  5. Beauty School student taking JAVA? doesn't work out so well, NEED HELP!
    By tmihans in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 20th, 2011, 07:58 AM