需要帮忙!!从方法返回值。 [英] Need help!! Returning a value from a method.

查看:80
本文介绍了需要帮忙!!从方法返回值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

更改此



Change this

public static isum(int a, int b)



到此:




to this:

public static int isum(int a, int b)



简单来说,任何方法在java中必须指定什么d atatype它将返回,在这种情况下是一个整数。



好​​像你是编程的新手,我建议你得到一本好的java书,以便有一个很好的理解。我推荐这个开始 - Java The Complete Reference [ ^ ]


这篇关于需要帮忙!!从方法返回值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆