0

This will not run, and I am pulling it straight from the how-to....

public class add
{ 
	public static void main(String[] args) 
	{ 
		int sum = add(5, 2);
		System.out.println("Sum is " + sum);
		
		public static int add(int firstInt, int secondInt)
		{
		return firstInt + secondInt;
		}
	}
}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Akill10
0

I would love to see the source you are pulling this from. You cannot create a method inside another method.

public class add
{ 
	public static void main(String[] args) 
	{ 
		int sum = add(5, 2);
		System.out.println("Sum is " + sum);
		
		public static int add(int firstInt, int secondInt)
		{
		return firstInt + secondInt;
		} //Wrong!
	}
}
public class add
{ 
	public static void main(String[] args) 
	{ 
		int sum = add(5, 2);
		System.out.println("Sum is " + sum);
		
		
	}
 public static int add(int firstInt, int secondInt)
		{
		return firstInt + secondInt;
		}//Right!
}

Edited by Akill10: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.