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 7 of 7

Thread: Simple Java Program

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Simple Java Program

    I have to make a program that will list all of the even numbers from 2-50. I have the basic part of it down but there is something wrong with it. The program is


    import java.io.*;
    class FilePrac3
    {
    public static void main (String args[])
    java.io.IOException
    {
    int count;
    for (int count = 2 ; count <= 50 ; count += 2)
    {
    System.out.println (count);
    System.out.println (count * count);
    }
    }
    }

    The error message says "Throws expected after this token".
    Any help would be greatly appreciated, thank you!


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Simple Java Program

    Youve got loads of irrelevant lines. and no need to declare 'count' integer twice. you do that in the first part of the for loop. Also you dont need the multiplication? You just want to print 2 4 6 8 10 12 etc. right?

    all you need is this:

            for (int count = 0; count <= 50; count += 2) {
                System.out.println(count);
     
            }
        }
    }

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Simple Java Program

    class FilePrac3
    {
    public static void main (String args[])
    java.io.IOException
    {
    for (int count = 0 ; count <= 50 ; count += 2)
    {
    System.out.println (count);

    }
    }
    }

    I made the change so now my program looks like this, but I still come up with the same error "Throws expected after this token"

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    20
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: Simple Java Program

    I don't know why you're using the line

    java.io.IOException

    try getting rid of that see if that works.

  5. The Following User Says Thank You to Henry518 For This Useful Post:

    Robbiep (October 23rd, 2011)

  6. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Simple Java Program

    Quote Originally Posted by Henry518 View Post
    I don't know why you're using the line

    java.io.IOException

    try getting rid of that see if that works.
    I tried it and it worked thank you! As you can tell I'm new to this so I'm making some silly mistake.

  7. #6
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Simple Java Program

    I'm willing to bet you're homework assignment asks you to print the numbers to a file, based on the calss name.

    If so, see Lesson: Basic I/O (The Java™ Tutorials > Essential Classes) for help

  8. #7
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Simple Java Program

    Quote Originally Posted by Robbiep View Post
    class FilePrac3
    {
    public static void main (String args[])
    java.io.IOException
    {
    for (int count = 0 ; count <= 50 ; count += 2)
    {
    System.out.println (count);

    }
    }
    }

    I made the change so now my program looks like this, but I still come up with the same error "Throws expected after this token"

    Like i said all you need is the lines i posted.

    Theres no need for any Exception handling here.

Similar Threads

  1. how to give inputs to my simple java program
    By pokuri in forum What's Wrong With My Code?
    Replies: 11
    Last Post: January 8th, 2011, 07:36 PM
  2. simple java console program, need help recalling commands
    By zero0000000 in forum Java Theory & Questions
    Replies: 2
    Last Post: October 22nd, 2010, 05:47 AM
  3. Need simple JAVA program fixing ASAP
    By theviper in forum Paid Java Projects
    Replies: 1
    Last Post: April 14th, 2010, 10:59 AM
  4. PLEASE HELP!!!! simple java program...
    By parvez07 in forum Object Oriented Programming
    Replies: 5
    Last Post: August 26th, 2009, 06:38 AM
  5. help with simple java program
    By parvez07 in forum Java Theory & Questions
    Replies: 4
    Last Post: August 25th, 2009, 07:19 AM