Contoh sederhana menambahkan dua nomor dengan memanggil metode
import java.util.Scanner;
class SumMethod{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.print("Enter the first number: ");
int num1=sc.nextInt();
System.out.print("Enter the second number: ");
int num2=sc.nextInt();
sc.close();
Sum(num1,num2);
}
//Sum method
public static void Sum(int num_A,int num_B){
int sum=0;
sum=num_A+num_B;
System.out.println("Sum of two numbers "+sum);
}
}
Outrageous Ostrich