How to create a package
At first create a folder like a name <cei> and store a program.
Listing 1: Sample showing Example using package. This is the package program
armstrong.java public class armstrong { int x=407; int r,temp,a=0; public void test() { temp=x; while(x>0) { r=x%10; a=a+(r*r*r); x=x/10; } if(temp==a) { System.out.println("This is Armstrong no.."); } else { System.out.println("This is not Armstrong no.."); } } }
After the creation of the program then compile this program with following syntax:
javac armstrong.java
If compile this part with successfully then write down this program.
Listing 2: Sample showing Example calling package
cal.java import cei.*; public class cal{ public static void main(String args[]){ armstrong ob=new armstrong(); ob.test(); //this part is calling package method } }
Then compile the code cal.java
javac cal.java
After that we interpreting this program cal.java
java cal
Then this call.java will be interpreted and run this program and show the output
Output:
This is Armstrong no.