Program to find greatest number between two numbers using function in java.
import java.util.*;
public class function {
public static int checkGreaterNumber(int a,int b){
if(a>b)
return a;
else
return b;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter two numbers=");
int a=sc.nextInt();
int b=sc.nextInt();
System.out.print("the greatest number is="+checkGreaterNumber(a,b));
}
}
■》Output->
enter two numbers=>
4
5
the greatest number is=5
Comments
Post a Comment