Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 29-Dec-12 17:53pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Change this
 
public static isum(int a, int b)
to this:
 
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[^]
  Permalink  
Comments
ridoy at 30-Dec-12 1:43am
   
exactly what needed..+5
TorstenH. at 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 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 458
1 Maciej Los 375
2 OriginalGriff 338
3 CHill60 205
4 Yogesh Kumar Tyagi 160
0 OriginalGriff 6,367
1 Sergey Alexandrovich Kryukov 5,296
2 Maciej Los 3,384
3 Peter Leow 3,259
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 30 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100