1. Create an application named Numbers whose main() method holds two integer variables. Assign
values to the variables. Pass both variables to methods named sum () and difference(). Create the
methods sum() and difference(); they compute the sum of and difference between the values of two
arguments, respectively. Each method should perform the appropriate computation and display the
results. Save the application as Numbers.cs
import java.util.Scanner;
public class Numbers {
public static void sum(int x, int y){
System.out.println("sum of two numbers: " + (x+y));
}
public static void difference(int x, int y){
System.out.println("difference of two numbers: " + (x-y));
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int x = in.nextInt();
System.out.print("Enter second number: ");
int y = in.nextInt();
Numbers.sum(x, y);
Numbers.difference(x, y);
}
}
Comments
Leave a comment