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

Thread: Java Class EASY Assignment

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Java Class EASY Assignment

    My problem is that I cannot get the method printMultiples to print. If I try to put a print statement in main it just says cannot find symbol, so I put the method in main and it works, but I have to use a method in my assignment. The program assigns N and a multiple and gets input from the user. The method printMultiples takes the variable n the user input and gets the first 6 multiples. My real question is how do i get n incorporated with printMultiples and get printMultiples to print?

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package factorial;
     
    /**
     *
     * @author student
     */
    import java.util.Scanner;
    public class Factorial {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            int n;
     
     
     
            Scanner reader = new Scanner (System.in);
            System.out.println("What Number?");
            n = reader.nextInt ();
     
     
     
            System.out.println(printMultiples);
     
     
     
        }
     
        public static void printMultiples (int n, int result) {
            int i = 1;
            while (i <=6) {
                System.out.print(n*i + "   ");
                i = i + 1;          
     
            }
            System.out.println("");
     
     
     
     
        }
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java Class EASY Assignment

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Jun 2012
    Posts
    105
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Java Class EASY Assignment

    There are a few options you can do to fix this problem. Since you're using a static method you can just literally call the method by typing in the name:
      int n;
     
     
     
            Scanner reader = new Scanner (System.in);
            System.out.println("What Number?");
            n = reader.nextInt ();
     
     
     
     
    printMultiples(100,10);
     
     
        }
     
        public static void printMultiples (int n, int result) {
            int i = 1;
            while (i <=6) {
                System.out.print(n*i + "   ");
                i = i + 1;          
     
            }
            System.out.println("");
     
     
     
     
        }
     
    }
    if you've remove the word static in your method, then you would have to call the method by making an object. Not sure if you want more details on that at this point, but I edited your code and I hope that helps.

  4. #4
    Member
    Join Date
    Jun 2012
    Posts
    105
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Java Class EASY Assignment

    I just put random numbers in there, because I didn't really know what arguments you wanted to pass into your static method.

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    21
    My Mood
    Confused
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: Java Class EASY Assignment

    printMultiples(n); //in the main....I think

Similar Threads

  1. class assignment
    By shanem in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 2nd, 2012, 01:23 PM
  2. Help with class assignment !
    By Ryoshiro in forum What's Wrong With My Code?
    Replies: 13
    Last Post: October 1st, 2012, 09:35 PM
  3. Please help a newbie with a easy java assignment!!
    By schoolbus11 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 26th, 2012, 02:19 AM
  4. Easy Tic Tac Toe game and Applet Assignment
    By Jmastersam in forum Java Theory & Questions
    Replies: 2
    Last Post: April 28th, 2012, 10:06 AM
  5. 1st Java class assignment, and having some difficulties. Little help please.
    By flpanthers1 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: May 27th, 2011, 04:09 AM