Sunday, 12 March 2023

1. Create a package P and within that package create class PackClass which have method called findmax( ) which find maximum value from three numbers. Now import the package within another class DemoClass and now display the maximum number.


/* file 1 Packclass.java */

package P;

public class Packclass
{
    public int findmax(int a,int b,int c)
    {
        int max = (a>b)? ((a>c)? a:c) : ((b>c)? b:c);
       
        return max;
    }
}

---------------------------------------------------------------------------

/* file 2 Program1.java */


import P.Packclass;
import java.util.*;

class Program1
{
    public static void main(String args[])
    {
        Packclass p1 = new Packclass();
        Scanner sc = new Scanner(System.in);
       
        System.out.print("enter three number: ");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
       
        System.out.println("\nmaximum number is: "+ p1.findmax(a,b,c));
       
    }
}


No comments:

Post a Comment

python programs

1. sum of two number