Functions – Java Program

Here is a simple Java Program that shows how to call a function.

Screen Shot 2018-04-12 at 10.50.41 PM


package function;

import java.util.Scanner;

public class fncn1st {
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter value for x: ");
int x = scan.nextInt();

Scanner scanII = new Scanner(System.in);
System.out.println("Enter value for y: ");
int y = scanII.nextInt();

int f = newFunction(x,y);
System.out.print("The function is equal to: "+f);

}

public static int newFunction(int a, int b)
{
int z;
z = ((a+b)/2);
return z;
}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s