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: maximum of two numbers method problem

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default maximum of two numbers method problem

    I just got introduced to methods and functions, and I have to use them to find the max of two integers entered by the user. Below is my code and the error I get is "cannot find symbol - variable maximum". Please any help on what I forgot to include?


     
     
    import java.util.Scanner;
     
    public class program4e_2
    {
     
          public static void main(String args[])
          {
              Scanner sc = new Scanner(System.in);
              System.out.println("Student 1, input your mark.");
              int x = sc.nextInt();
              System.out.println("Student 2, input your mark.");
              int y = sc.nextInt();
              int value =  maximum(x,y);
              System.out.println(maximum);
     
     
            }
            static public int maximum(int x,int y)
            {
                return Math.max(x,y);
            }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: maximum of two numbers method problem

    cannot find symbol - variable maximum
    The compiler can not find a variable named maximum. Look at the code and find the name of the variable that you want to print. maximum is the name of a method that the code calls.

    You probably should NOT use the Math.max() method in the maximum() method. I would expect your instructor to want you to use an if statement to find the max value to be returned.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: maximum of two numbers method problem

    Quote Originally Posted by Norm View Post
    The compiler can not find a variable named maximum. Look at the code and find the name of the variable that you want to print. maximum is the name of a method that the code calls.

    You probably should NOT use the Math.max() method in the maximum() method. I would expect your instructor to want you to use an if statement to find the max value to be returned.
    Oh wow I'm an idiot

    I have to print 'value' not maximum, thanks.

Similar Threads

  1. Maximum Space Usage Recursion Problem
    By NerdFail in forum Algorithms & Recursion
    Replies: 0
    Last Post: November 24th, 2012, 09:36 PM
  2. if problem with range of numbers
    By deependeroracle in forum Loops & Control Statements
    Replies: 3
    Last Post: February 17th, 2012, 05:33 AM
  3. [METHOD] How: Count how many prime numbers there is between two numbers!
    By Secret20 in forum Object Oriented Programming
    Replies: 4
    Last Post: October 18th, 2011, 02:30 PM
  4. execute a method over a maximum period of time
    By PedroCosta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 24th, 2011, 02:06 PM