Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 = new 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

What populates the Smalltalk world?

Answered: 1 week ago