Click here to Skip to main content
15,884,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
import java.util.Scanner;
public class sum_number
{
	public static void main(String[] args)
	{
		int a,b,c, sum;
		Scanner input = new Scanner(System.in);

		System.out.print("Enter any number:\n");
		a = input.nextInt();

		System.out.print("Enter another number:");
		b = input.nextInt();

		isum(a,b);

		System.out.print("The addtion result of the entered numbers is: " +z);
	}

	public static isum(int a, int b)

	{
		int z;
		z= a+b;
		return z;
	}

}


//Here is the result what I got. Please help me by correcting this code:

C:\Users\Sanjib\Documents\sum_number.java:20: invalid method declaration; return type required
	public static isum(int a, int b)
	              ^
1 error

Tool completed with exit code 1
Posted

1 solution

Change this

Java
public static isum(int a, int b)

to this:

Java
public static int isum(int a, int b)

In simple words, any method in java has to specify what datatype it will be returning, in this case an integer.

Seems like you are new to programming, I advice you to get a good java book to have a good understanding. I recommend this to get started - Java The Complete Reference[^]
 
Share this answer
 
Comments
ridoy 30-Dec-12 1:43am    
exactly what needed..+5
TorstenH. 30-Dec-12 2:44am    
...and please use a IDE like Eclipse or Netbeans. Both are free and both would show you those errors.
suhan 2012 31-Dec-12 5:20am    
I changed the line as what Karthik said, but found no improvement. BTW I am using "Java Programming by Joyce Farrell". Is this a good book for me as a beginner? Waiting for your reply..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900