0% found this document useful (0 votes)
19 views

Oops 18-31

Uploaded by

Alvin Saji John
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Oops 18-31

Uploaded by

Alvin Saji John
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

‭PROGRAM‬

i‭mport java.util.*;‬
‭public class binary‬
‭{‬
‭public static void main(String[] args)‬
‭{‬
‭ArrayList<Integer>BSearch=new ArrayList<Integer>();‬
‭Scanner sd=new Scanner(System.in);‬
‭int i,j,key;‬
‭System.out.println("Binary Search \nEnter the number of elements:");‬
‭int lim=sd.nextInt();‬
‭System.out.println("Enter the elements:");‬
‭for(i=0;i<lim;i++)‬
‭BSearch.add(sd.nextInt());‬
‭for(i=0;i<lim;i++)‬
‭{‬
‭for(j=0;j<lim;j++)‬
‭{‬
‭if(BSearch.get(j)>BSearch.get(j+1))‬
‭{‬
‭int temp=BSearch.get(j);‬
‭BSearch.set(j,BSearch.get(j+1));‬
‭BSearch.set(j+1,temp);‬
‭}‬
‭}‬
‭}‬
‭System.out.println("Enter element to search:");‬
‭key=sd.nextInt();‬
‭int mid,low=0,high=(lim-1);‬
‭while(low<=high)‬
‭{‬
‭mid=(low+high)/2;‬
‭if(BSearch.get(mid)==key)‬
‭{‬
‭System.out.println(key+"Found in ArrayList at"+(mid+1));‬
‭break;‬
‭}‬
‭else if(BSearch.get(mid)>key)‬
‭high=mid-1;‬
‭else‬
‭low=mid+1;‬
‭}‬
‭if(low>high)‬
‭System.out.println(key+"Not Found");‬
‭}‬
‭}‬
‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac binary.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java binary‬
‭Binary Search‬
‭Enter the number of elements:‬
‭4‬
‭Enter the elements:‬
‭1‬
‭5‬
‭2‬
‭7‬
‭Enter element to search:‬
‭5‬
‭5 Found in ArrayList‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭class Stack‬
‭{‬
‭int top=-1;‬
‭int n;‬
‭Stack(int N)‬
‭{‬
‭n=N;‬
‭}‬
‭int stack[]=new int[10];‬
‭void push(int a)‬
‭{‬
‭if(top==n-1)‬
‭System.out.println("Stack Overflow.");‬
‭else‬
‭{‬
‭top=top+1;‬
‭stack[top]=a;‬
‭}‬
‭}‬
‭void pop()‬
‭{‬
‭if(top==-1)‬
‭System.out.println("Stack Underflow.");‬
‭else‬
‭{‬
‭System.out.println("Deleted element is: "+stack[top]);‬
‭top--;‬
‭}‬
‭}‬
‭void display()‬
‭{‬
‭System.out.println("Elements in Stack are: ");‬
‭for(int i=0;i<=top;i++)‬
‭System.out.print(stack[i]+"");‬
‭}‬
‭}‬
‭class StackMain‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭Scanner sc=new Scanner(System.in);‬
‭System.out.print("Enter the size:");‬
‭int max=sc.nextInt();‬
‭Stack stk=new Stack(max);‬
‭System.out.println("*MENU*\n1.Push\n2.Pop\n4.Display\n5.Exit");‬
‭ hile(true)‬
w
‭{‬
‭System.out.print("\nEnter your choice: ");‬
‭int ch=sc.nextInt();‬
‭switch(ch)‬
‭{‬
‭case 1:‬
‭{‬
‭System.out.print("Enter the element: ");‬
‭int ele=sc.nextInt();‬
‭stk.push(ele);‬
‭break;‬
‭}‬
‭case 2:‬
‭{‬
‭stk.pop();‬
‭break;‬
‭}‬
‭case 3:‬
‭{‬
‭stk.display();‬
‭break;‬
‭}‬
‭case 4:‬
‭{‬
‭System.out.println("Program Terminated");‬
‭System.exit(0);‬
‭}‬
‭}‬
‭}‬
‭}‬
‭}‬

‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac StackMain.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java StackMain‬
‭Enter the size:3‬
‭*MENU*‬
‭1.Push‬
‭2.Pop‬
‭3.Display‬
‭4.Exit‬

‭ nter your choice: 1‬


E
‭Enter the element: 2‬
‭ nter your choice: 1‬
E
‭Enter the element: 3‬

‭ nter your choice: 1‬


E
‭Enter the element: 4‬

‭ nter your choice: 1‬


E
‭Enter the element: 5‬
‭Stack Overflow.‬

‭ nter your choice: 2‬


E
‭Deleted element is: 4‬

‭ nter your choice: 3‬


E
‭Elements in Stack are:‬
‭23‬
‭Enter your choice: 4‬
‭Program Terminated‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭class Queue‬
‭{‬
‭int front=-1,rear=-1;‬
‭int n; Queue(int N)‬
‭{‬
‭n=N;‬
‭}‬
‭int queue[]=new int[10];‬
‭void insert(int a)‬
‭{‬
‭if(rear==n-1)‬
‭System.out.println("Queue Full");‬
‭else if((front==-1)&&(rear==-1))‬
‭{‬
‭front=0;‬
‭rear=0;‬
‭queue[rear]=a;‬
‭}‬
‭else‬
‭{‬
‭rear=rear+1;‬
‭queue[rear]=a;‬
‭}‬
‭}‬
‭void delete()‬
‭{‬
‭if((front==-1&&rear==-1)||(front>rear))‬
‭System.out.println("Queue Empty");‬
‭else‬
‭{‬
‭System.out.println("Deleted element is:"+queue[front]);‬
‭front++;‬
‭}‬
‭}‬
‭void display()‬
‭{‬
‭System.out.println("Elements of the queue are:");‬
‭for(int i=front;i<=rear;i++)‬
‭System.out.println(queue[i]+"");‬
‭}‬
‭}‬
‭class QueueMain‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭ canner sc=new Scanner(System.in);‬
S
‭System.out.println("Enter the size of Queue:");‬
‭int max=sc.nextInt();‬
‭Queue q=new Queue(max);‬
‭System.out.println("**MENU**\n1.Insert\n2.Delete\n3.Display\n4.Exit");‬
‭while(true)‬
‭{‬
‭System.out.println("\nEnter your choice:");‬
‭int ch=sc.nextInt();‬
‭switch(ch)‬
‭{‬
‭case 1:‬
‭{‬
‭System.out.println("Enter the element:");‬
‭int ele=sc.nextInt();‬
‭q.insert(ele);‬
‭break;‬
‭}‬
‭case 2:‬
‭{‬
‭q.delete();‬
‭break;‬
‭}‬
‭case 3:‬
‭{‬
‭q.display();‬
‭break;‬
‭}‬
‭case 4:‬
‭{‬
‭System.out.println("Program Terminated");‬
‭System.exit(0);‬
‭}‬
‭}‬
‭}‬
‭}‬
‭}‬

‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac QueueMain.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java QueueMain‬

‭ nter the size of Queue:‬


E
‭3‬
‭ *MENU**‬
*
‭1.Insert‬
‭2.Delete‬
‭3.Display‬
‭4.Exit‬
‭Enter your choice: 1‬
‭Enter the element: 1‬

‭ nter your choice: 1‬


E
‭Enter the element: 2‬

‭ nter your choice: 1‬


E
‭Enter the element: 3‬

‭ nter your choice: 3‬


E
‭Elements of the queue are: 1 2 3‬

‭ nter your choice: 2‬


E
‭Deleted element is:1‬

‭ nter your choice: 4‬


E
‭Program Terminated‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭interface Test‬
‭{‬
‭int square(int n);‬
‭}‬
‭class Arithmetic implements Test‬
‭{‬
‭public int square(int n)‬
‭{‬
‭return n*n;‬
‭}‬
‭}‬
‭class InterfaceSquare‬
‭{‬
‭public static void main(String[] args)‬
‭{‬
‭Scanner sc=new Scanner(System.in);‬
‭Arithmetic ob=new Arithmetic();‬
‭System.out.println("Enter a number:");‬
‭int n=sc.nextInt();‬
‭int result=ob.square(n);‬
‭System.out.println("The square of is"+result);‬
‭}‬
‭}‬

‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac InterfaceSquare.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java InterfaceSquare‬

‭ nter a number:‬
E
‭5‬
‭The square of is 25‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭class Bubblesort‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭ArrayListlist=new ArrayList();‬
‭Scanner sc=new Scanner(System.in);‬
‭System.out.println("Enter the size of the array:");‬
‭int n=sc.nextInt();‬
‭System.out.println("Enter the elements in the array:");‬
‭for(int i=0;i<n;i++)‬
‭{‬
‭Int x=sc.nextInt();‬
‭list.add(x);‬
‭}‬
‭for(int i=0;i<n;i++)‬
‭{‬
‭for(int j=0;j<n;j++)‬
‭{‬
‭if(list.get(j)>list.get(j+1))‬
‭{‬
‭int temp=list.get(j);‬
‭list.set(j,list.get(j+1));‬
‭list.set(j+1,temp);‬
‭}‬
‭}‬
‭}‬
‭System.out.println("Sorted Array:");‬
‭Iterator<Integer>it=list.iterator(); while(it.hasNext()) { System.out.println(it.next()+"");‬
‭}‬
‭}‬
‭}‬

‭OUTPUT‬
‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac Bubblesort.java‬
u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java Bubblesort‬
‭Enter the size of the array: 3‬
‭Enter the elements in the array:‬
‭7‬
‭1‬
‭9‬
‭Sorted Array:‬
‭1‬
‭7‬
‭9‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭class LinkedListEx‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭LinkedListlist<Integer>=new LinkedLis<Integer>();‬
‭Scanner sc=new Scanner(System.in);‬
‭System.out.println("**MENU**\n1.Create\n2.Delete\n3.Display\n4.Exit");‬
‭while(true)‬
‭{‬
‭System.out.println("\nChoose an option:");‬
‭int ch=sc.nextInt();‬
‭switch(ch)‬
‭{‬
‭case 1:‬
‭System.out.println("Enter number of elements:");‬
‭int n=sc.nextInt();‬
‭System.out.println("Enter the elements:");‬
‭for(int i=0;i<n;i++)‬
‭{‬
‭int a=sc.nextInt();‬
‭list.add(a);‬
‭}‬
‭break;‬
‭case 2:‬
‭System.out.println("Enter index to remove:");‬
‭int pos=sc.nextInt();‬
‭System.out.println("The deleted element is:"+list.get(pos));‬
‭list.remove(pos);‬
‭break;‬
‭case 3:‬
‭Iterator<Integer>it=list.iterator();‬
‭while(it.hasNext())‬
‭{‬
‭System.out.println(it.next()+"");‬
‭}‬
‭break;‬
‭case 4:‬
‭System.out.println("Exiting the program...");‬
‭System.exit(0);‬
‭}‬
‭}‬
‭}‬
‭}‬
‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac LinkedListEx.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java LinkedListEx‬

‭ *MENU**‬
*
‭1.Create‬
‭2.Delete‬
‭3.Display‬
‭4.Exit‬

‭ hoose an option:1‬
C
‭Enter number of elements: 2‬
‭Enter the elements: 1 2‬

‭ hoose an option: 2‬
C
‭Enter index to remove: 1‬
‭The deleted element is:2‬

‭ hoose an option: 3‬
C
‭1‬

‭ hoose an option: 4‬
C
‭Exiting the program...‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭class ArrayListEx‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭ArrayList<Integer>list=new ArrayList<Integer>();‬
‭Scanner sc=new Scanner(System.in);‬
‭System.out.println("**MENU**\n1.Insert\n2.Delete\n3.Display\n4.Exit");‬
‭while(true)‬
‭{‬
‭System.out.println("\nChoose an option:");‬
‭int ch=sc.nextInt();‬
‭switch(ch)‬
‭{‬
‭case 1:‬
‭System.out.println("Enter the element to insert:");‬
‭int n=sc.nextInt();‬
‭list.add(n);‬
‭break;‬
‭case 2:‬
‭System.out.println("Enter index to remove:");‬
‭int pos=sc.nextInt();‬
‭System.out.println("The deleted element:"+list.get(pos));‬
‭list.remove(pos);‬
‭break;‬
‭case 3: Iterator<Integer>it=list.iterator<Integer>();‬
‭while(it.hasNext())‬
‭{‬
‭System.out.println(it.next()+"");‬
‭}‬
‭break;‬
‭case 4:‬
‭System.out.println("Exiting the program...");‬
‭System.exit(0);‬
‭}‬
‭}‬
‭}‬
‭}‬

‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac ArrayListEx.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java ArrayListEx‬
‭ *MENU**‬
*
‭1.Insert‬
‭2.Delete‬
‭3.Display‬
‭4.Exit‬

‭ hoose an option: 1‬
C
‭Enter the element to insert: 2‬

‭ hoose an option: 1‬
C
‭Enter the element to insert: 3‬

‭ hoose an option: 2‬
C
‭Enter index to remove: 1‬
‭The deleted element:3‬

‭ hoose an option: 3‬
C
‭2‬

‭ hoose an option: 4‬
C
‭Exiting the program...‬
‭PROGRAM‬

i‭mport java.io.*;‬
‭import java.lang.*;‬
‭import java.util.*;‬
‭class stringtoken‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭int n;‬
‭int sum = 0;‬
‭Scanner sc = new Scanner(System.in);‬
‭System.out.print("Enter integer seperated by space : ");‬
‭String s = sc.nextLine();‬
‭StringTokenizer st = new StringTokenizer(s," ");‬
‭while(st.hasMoreTokens())‬
‭{‬
‭String temp = st.nextToken();‬
‭n = Integer.parseInt(temp);‬
‭System.out.println(n);‬
‭sum = sum+n;‬
‭}‬
‭System.out.println("Sum of INTEGERS is "+sum);‬
‭}‬
‭}‬

‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac stringtoken.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java stringtoken‬

‭ nter integer seperated by space : 2 3‬


E
‭2‬
‭3‬
‭Sum of INTEGERS is 5‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭class Synchronization extends Thread‬
‭{‬
‭public void display(int x)‬
‭{‬
‭System.out.println("Square of "+x+" is "+(x*x));‬
‭}‬
‭synchronized public void run()‬
‭{‬
‭String name=Thread.currentThread().getName();‬
‭if(name.equals("t1"))‬
‭{‬
‭display(2);‬
‭}‬
‭else if(name.equals("t2"))‬
‭{‬
‭display(3);‬
‭}‬
‭else‬
‭{‬
‭display(4);‬
‭}‬
‭}‬
‭public static void main(String args[])‬
‭{‬
‭Synchronization s=new Synchronization();‬
‭Thread t1=new Thread(s);‬
‭Thread t2=new Thread(s);‬
‭Thread t3=new Thread(s);‬
‭t1.setName("t1");‬
‭t2.setName("t2");‬
‭t3.setName("t3");‬
‭t1.start();‬
‭t2.start();‬
‭t3.start();‬
‭}‬
‭}‬

‭OUTPUT‬
‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac Synchronization.java‬
u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java Synchronization‬

‭ quare of 2 is 4‬
S
‭Square of 4 is 16‬
‭Square of 3 is 9‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭class OddThread extends Thread‬
‭{‬
‭int cube;‬
‭OddThread(int cube)‬
‭{‬
‭this.cube=cube;‬
‭}‬
‭public void run()‬
‭{‬
‭if(cube<0)‬
‭cube=cube*(-1);‬
‭System.out.println("Cube of "+cube+"is: "+cube*cube*cube);‬
‭}‬
‭}‬
‭class EvenThread extends Thread‬
‭{‬
‭int sq;‬
‭EvenThread(int sq)‬
‭{‬
‭this.sq=sq;‬
‭}‬
‭public void run()‬
‭{‬
‭if(sq>0)‬
‭sq=sq*(-1);‬
‭System.out.println("Square of "+sq+"is: "+sq*sq);‬
‭}‬
‭}‬
‭class RandThread extends Thread‬
‭{‬
‭int n;‬
‭RandThread(int n)‬
‭{‬
‭this.n=n;‬
‭}‬
‭public void run()‬
‭{‬
‭Random r=new Random();‬
‭for(int i=0;i<n;i++)‬
‭{‬
‭int nn=r.nextInt(100);‬
‭if(nn%2==0)‬
‭{‬
‭EvenThread t2=new EvenThread(nn);‬
t‭2.start();‬
‭}‬
‭else‬
‭{‬
‭OddThread t3=new OddThread(nn);‬
‭t3.start();‬
‭}‬
‭try‬
‭{‬
‭Thread.sleep(1000);‬
‭}‬
‭catch(Exception e)‬
‭{‬
‭System.out.println(e);‬
‭}‬
‭}‬
‭}‬
‭}‬
‭class multithread‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭Scanner sc=new Scanner(System.in);‬
‭System.out.println("Enter limit: ");‬
‭int l=sc.nextInt();‬
‭RandThread t1=new RandThread(l);‬
‭t1.start();‬
‭}‬
‭}‬

‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac multithread.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java multithread‬
‭Enter limit: 5‬
‭Square of -22is: 484‬
‭Square of -52is: 2704‬
‭Square of -24is: 576‬
‭Cube of 37is: 50653‬
‭Square of -50is: 2500‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭class NegativeExceptionHandling‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭Scanner sc=new Scanner(System.in);‬
‭try‬
‭{‬
‭System.out.println("Enter the size of array:");‬
‭int n=sc.nextInt();‬
‭int a[]=new int[n];‬
‭}‬
‭catch(Exception e)‬
‭{‬
‭System.out.println("Array size is negative!!");‬
‭System.out.println(e);‬
‭}‬
‭}‬
‭}‬

‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac NegativeExceptionHandling.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ NegativeExceptionHandling‬

‭ nter the size of array: -5‬


E
‭Array size is negative!!‬
‭java.lang.NegativeArraySizeException: -5‬
‭PACKAGE PROGRAM‬

‭ ackage NewPackage;‬
p
‭public class Parity‬
‭{‬
‭public String parityCheck(int n)‬
‭{‬
‭System.out.println(“**Operating from package**\n”);‬
‭if(n%2==0)‬
‭return “even”;‬
‭else‬
‭return “odd”;‬
‭}‬
‭}‬

‭MAIN PROGRAM‬

i‭mport java.util.Scanner;‬
‭import NewPackage.Parity;‬
‭class Newclass‬
‭{‬
‭public static void main(String[] args)‬
‭{‬
‭Parity obj=new Parity();‬
‭Scanner input=new Scanner(System.in);‬
‭int n;‬
‭System.out.println(“**Displaying from main program**\n”);‬
‭System.out.println(“Enter a number:”);‬
‭n=input.nextInt();‬
‭System.out.println(“%d is %s\n”,n,obj.parityCheck(n));‬
‭}‬
‭}‬

‭OUTPUT‬
‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac -d.Newclass.java‬
u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ Newclass‬

‭ nter the number:‬


E
‭2‬
‭2 is even‬
‭ubuntu@L5SYS10:~/Desktop/sco1026923$java Parity‬
‭Enter the number:‬
‭5‬
‭5 is odd‬
‭PROGRAM‬

i‭mport java.util.*;‬
‭class NegativeException‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭int n,i;‬
‭float sum=0,avg;‬
‭try‬
‭{‬
‭n=Integer.parseInt(args[0]);‬
‭if(n==0||n<0)‬
‭throw new IllgealArgumentException();‬
‭else‬
‭{‬
‭for(i=1;i<=n;i++)‬
‭{‬
‭sum=sum+i;‬
‭}‬
‭avg=sum/n;‬
‭System.out.println(“Average is:”+avg);‬
‭}‬
‭}‬
‭catch(IllegalArgumentException e)‬
‭{‬
‭System.out.println(“Invalid Number Exception!!!”);‬
‭}‬
‭}‬
‭}‬

‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac NegativeException.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java NegativeException‬

‭ nter the number : 5‬


E
‭Average is : 3.0‬
‭Enter the number : 0‬
‭Invalid Number Exception!!!‬
‭Enter the number : 1‬
‭Invalid Number Exception!!!‬
‭PACKAGE PROGRAM‬

‭ ackage primepack;‬
p
‭public class PrimePack‬
‭{‬
‭public void prime(int n)‬
‭{‬
‭if(n==0||n==1)‬
‭{‬
‭System.out.println(“Not a prime number:”);‬
‭}‬
‭else‬
‭{‬
‭int I;‬
‭int flag=0;‬
‭for(i=2;i<n/2;i++)‬
‭{‬
‭if(n%i==0)‬
‭{‬
‭System.out.println(n+”is not prime”);‬
‭flag=1;‬
‭break;‬
‭}‬
‭}‬
‭if(flag==0)‬
‭{‬
‭System.out.println(n+”is a prime number”);‬
‭}‬
‭}‬
‭}‬
‭}‬

‭MAIN PROGRAM‬

i‭mport primepack.PrimePack;‬
‭import java.util.*;‬
‭class PrimePkg‬
‭{‬
‭public static void main(String args[])‬
‭{‬
‭Scanner sc=new Scanner(System.in);‬
‭System.out.println(“Enter the number:”);‬
‭int n=sc.nextInt();‬
‭PrimePack obj=new PrimePack();‬
‭obj.prime(n);‬
‭}‬
‭}‬
‭OUTPUT‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ javac -d.PrimePkg.java‬


u
‭ubuntu@l0sys10:-/Desktop/SCO1023723$ java PrimePkg‬

‭ nter the number : 13‬


E
‭13 is a prime number‬

‭ buntu@l0sys10:-/Desktop/SCO1023723$ java PrimePkg‬


u
‭Enter the number : 0‬
‭Not a prime number‬

You might also like