Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to display the smallest number in stack on java

a48b83c2-9191-4110-8dff-2b8afd3e2e4bJan 11 2018 — edited Oct 28 2018

Hi, I'm using netBeans IDE, and I need help with,

I have the following code, and I want a simple method to print the smallest number in stack, I so beginner so if you can please write a very simple method to me

class stack1 {
  int maxsize,top;
  //String arr[];
  public int arr[];
  int maxsize1;
  stack1 (int maxsize){
  this.maxsize=maxsize;
  arr=new int[maxsize];
  top=0;
  }
  void push (int data) {
  if (top<maxsize) {
  arr[top]=data;
  top++;}
  else System.out.print("stack is overflow");
  }

  void main(String arg[]) {

stack1 s=new stack1(4);
s.push(1);
s.push(10);
s.push(3);
s.push(9);
}
}

I also have a code to display a maxumi

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 25 2018
Added on Jan 11 2018
4 comments
940 views