Wednesday, 7 March 2018
How to find Min and Max value from stack
Its very simple.
1. Sort the value in stack using Collections.sort()
2.then find the min by using Collections.min()
3.find the max bu using Collections.max() method
package ListExample;
import java.util.Collections;
import java.util.Stack;
public class StackExample {
public static void main(String[] args) {
Stack stack = new Stack();
stack.push(12);
stack.push(12);
stack.push(9);
stack.push(25);
stack.push(55);
stack.push(65);
System.out.println(stack);//printing without sorting
Collections.sort(stack);//Sorting the stack
System.out.println("Max number is "+Collections.max(stack));//Printing Max number in stack
System.out.println("Min number is "+Collections.min(stack));//Return Minimum number in stack
}
}
1. Sort the value in stack using Collections.sort()
2.then find the min by using Collections.min()
3.find the max bu using Collections.max() method
package ListExample;
import java.util.Collections;
import java.util.Stack;
public class StackExample {
public static void main(String[] args) {
Stack stack = new Stack();
stack.push(12);
stack.push(12);
stack.push(9);
stack.push(25);
stack.push(55);
stack.push(65);
System.out.println(stack);//printing without sorting
Collections.sort(stack);//Sorting the stack
System.out.println("Max number is "+Collections.max(stack));//Printing Max number in stack
System.out.println("Min number is "+Collections.min(stack));//Return Minimum number in stack
}
}
Subscribe to:
Posts (Atom)
session-per-request in hibernate
The most common pattern in a multi-user client/server application is session-per-request . In this model, a request from the client is sent...
-
The most common pattern in a multi-user client/server application is session-per-request . In this model, a request from the client is sent...
-
Ans.. Here we can count the character occurrence in String in very simple way. first we have to declare String that for every character ...
-
you can call it as many times and anywhere you like once you get hold of your org.hibernate.SessionFactory. The getCurrentSession() method ...