Question
Intro to JAVA Simple Programing 1. Please write the code according to the instruction, such as line of code required etc, in bold. import java.util.Stack
Intro to JAVA Simple Programing 1.
Please write the code according to the instruction, such as line of code required etc, in bold.
import java.util.Stack ;
/**
Practices using the Stack from the Java API.
*/
public class StackApiTester
{
public static void main(String[] args)
{
Stack
stack.push("horse") ;
stack.push("cat") ;
stack.push("dog") ;
stack.push("cow") ;
stack.push("mouse") ;
System.out.println(stack.pop()) ;
System.out.println(stack.pop()) ;
System.out.println(stack.pop()) ;
System.out.println(stack.peek()) ;
System.out.println("stack is empty? " + stack.isEmpty()) ;
System.out.println(stack.pop()) ;
System.out.println("stack is empty? " + stack.isEmpty()) ;
System.out.println(stack.pop()) ;
System.out.println("stack is empty? " + stack.isEmpty()) ;
//-----------Start below here. To do: approximate lines of code = 8
// 1. make a stack that holds integers ;
//2. push in the integers from 1 to 100 that are divisible by 3 ;
//3. print the size ;
//4. while stack not empty ;
//5. let value hold pop ;
//6. if value divisible by 9 then print it.
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started