Page 240 - CA_Blue( J )_Class10
P. 240
27 System.out.println(n + " is a perfect number ");
28 else
29 System.out.println(n + " is not a perfect number ");
30 }
31 }
Program 2 To input three numbers and print the greatest number using the function greater ().
1 import java.util.*;
2 class greater_function
3 {
4 public static int greater (int a, int b, int c)
5 {
6 int g;
7 g=(a>b)? (a>c)? a:c:(b>c)? b:c;
8 return g;
9 }
10
11 public static void main ()
12 {
13 Scanner sc= new Scanner (System.in);
14 int n1, n2, n3;
15 System.out.println("Enter three numbers: ");
16 n1=sc.nextInt();
17 n2=sc.nextInt();
18 n3=sc.nextInt();
19 System.out.println(greater(n1, n2, n3) + " is the largest number ");
20 }
21 }
238238 Touchpad Computer Applications-X

