OOPPS
OOPPS
import java.util.*;
/* Class arrayStack */
class StackADT
{
int array[];
int top, size, len;
Scanner in=new
Scanner(System.in)
;
/* Constructor for arrayStack */
public StackADT(int n)
{
size = n;
len = 0;
array = new
int[size]; top = -1;
}
/* Function to check if stack is empty
*/ public boolean isEmpty()
{
return top == -1;
}
/* Function to check if stack is full
*/ public boolean isFull()
{
return top == size -1 ;
}
/* Function to get the size of the stack */
public int getSize()
{
return len ;
}
/* Function to check the top element of the stack
*/ public int peek()
{
211423243501 YUGANDRAN D
if( isEmpty() )
throw new NoSuchElementException("Underflow Exception");
return array[top];
}
/* Function to add an element to the stack
*/ public void push()
{
if(top + 1 >= size)
throw new IndexOutOfBoundsException("Overflow Exception");
if(top + 1 < size )
{
System.out.println("Enter integer element to push"); array[++top]
= in.nextInt();
}
len++ ;
}
/* Function to delete an element from the
stack */ public int pop()
{
if( isEmpty() )
throw new NoSuchElementException("Underflow Exception");
len-- ;
return array[top--];
}
/* Function to display the status of the stack */
public void display()
{
System.out.print("\nStack =
"); if (len == 0)
{
System.out.print("Empty\
n"); return ;
}
for (int i = top; i >= 0; i--)
System.out.print(array[i]+"
");
System.out.println();
}
}
211423243501 YUGANDRAN D
public class Stack_Main
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Stack Test\n");
try
{
stk.push();
}
catch (Exception e)
{
System.out.println("E
rror : " +
e.getMessage());
}
break;
211423243501 YUGANDRAN D
case 2 :
try
{
System.out.println("Popped Element = " + stk.pop());
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}
break;
case 3 :
try
{
S
yst
em.
out.
pri
ntln
("P
eek
Ele
me
nt
="
+
stk.
pee
k())
;
}
cat
ch
(Exce
ption
e)
{
S
yst
em.
out.
pri
ntln
("E
rror
:"
+
e.g
et
211423243501 Me
ssa YUGANDRAN D
OUTPUT:
211423243501 YUGANDRAN D
211423243501 YUGANDRAN D
211423243501 YUGANDRAN D
PROGRAM
import java.util.Random;
public EvenNum(int x) {
this.x = x;
}
211423243501 YUGANDRAN D
public void run() {
for (int i = 0; i < iterations; i++) {
int num = r.nextInt(11); // Generate a number between 0 and 10 if
(num % 2 == 0) {
new Thread(new EvenNum(num)).start();
} else {
new Thread(new OddNum(num)).start();
}
try {
Thread.sleep(100); // Sleep for 100ms
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
211423243501 YUGANDRAN D
OUTPUT
211423243501 YUGANDRAN D
PROGRAM
import java.io.*;
import
java.util.*;
public class
MaximumTest {
public static <T
extends
Comparable<T>
> T maximum(T
x, T y, T z) {
T max = x; // Assume x is the largest initially
if (y.compareTo(max) > 0) {
max = y; // y is the largest so far
}
if (z.compareTo(max) > 0)
{ max = z; // z is the largest
now
}
return max; // returns the largest
object
}
a = s.nextInt();
b = s.nextInt();
c = s.nextInt();
211423243501 YUGANDRAN D
OUTPUT
211423243501 YUGANDRAN D