SlideShare a Scribd company logo
1 of 2
Download to read offline
Write the code for a small function called myStack, which creates a Stack object of String
elements, named cities. Add "Sydney", then "London", then "New York" and then
"Beijing" to cities. Then print each element on the screen, one per line. Print each element in a
way that causes cities to be empty (i.e. have 0 elements) afterwards. (6 mks)
Solution
PROGRAM CODE:
package stack;
import java.util.Stack;
public class MyStackClass {
//stack function
public static void myStack()
{
//creating a stack object called cities
Stack cities = new Stack();
//Adding cities into the stack
cities.push("Sydney");
cities.push("London");
cities.push("New York");
cities.push("Beijing");
//using while loop to loop through the stack till its empty
while(!cities.isEmpty())
{
// pop function is used to remove elements from the stack
// pop() returns the elemets which is printed on the csreen
System.out.println(cities.pop());
}
}
// Main function for the class
public static void main(String args[])
{
myStack(); // function call to the stack method
}
}
OUTPUT:
Beijing
New York
London
Sydney

More Related Content

Similar to Write the code for a small function called myStack, which creates a .pdf

Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016Mikhail Sosonkin
 
KDD 2016 Streaming Analytics Tutorial
KDD 2016 Streaming Analytics TutorialKDD 2016 Streaming Analytics Tutorial
KDD 2016 Streaming Analytics TutorialNeera Agarwal
 
Constructors-Destructors Extend the Stack-h class given in order for i.pdf
Constructors-Destructors Extend the Stack-h class given in order for i.pdfConstructors-Destructors Extend the Stack-h class given in order for i.pdf
Constructors-Destructors Extend the Stack-h class given in order for i.pdf21stcenturyjammu21
 
Don't Make Android Bad... Again
Don't Make Android Bad... AgainDon't Make Android Bad... Again
Don't Make Android Bad... AgainPedro Vicente
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom componentsJeremy Grancher
 
Modify the Stack class given in the book in order for it to store do.pdf
Modify the Stack class given in the book in order for it to store do.pdfModify the Stack class given in the book in order for it to store do.pdf
Modify the Stack class given in the book in order for it to store do.pdffathimafancy
 
Tutorial 6 queues & arrays & results recording
Tutorial 6   queues & arrays & results recording Tutorial 6   queues & arrays & results recording
Tutorial 6 queues & arrays & results recording Mohd Batati
 
Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Stacy Devino
 
Stack Implementation
Stack ImplementationStack Implementation
Stack ImplementationZidny Nafan
 
Given the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxGiven the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxshericehewat
 
iOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + GherkiniOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + GherkinKenneth Poon
 

Similar to Write the code for a small function called myStack, which creates a .pdf (20)

Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016
 
Interaksi obyek
Interaksi obyekInteraksi obyek
Interaksi obyek
 
KDD 2016 Streaming Analytics Tutorial
KDD 2016 Streaming Analytics TutorialKDD 2016 Streaming Analytics Tutorial
KDD 2016 Streaming Analytics Tutorial
 
Constructors-Destructors Extend the Stack-h class given in order for i.pdf
Constructors-Destructors Extend the Stack-h class given in order for i.pdfConstructors-Destructors Extend the Stack-h class given in order for i.pdf
Constructors-Destructors Extend the Stack-h class given in order for i.pdf
 
Don't Make Android Bad... Again
Don't Make Android Bad... AgainDon't Make Android Bad... Again
Don't Make Android Bad... Again
 
LectureNotes-06-DSA
LectureNotes-06-DSALectureNotes-06-DSA
LectureNotes-06-DSA
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
Modify the Stack class given in the book in order for it to store do.pdf
Modify the Stack class given in the book in order for it to store do.pdfModify the Stack class given in the book in order for it to store do.pdf
Modify the Stack class given in the book in order for it to store do.pdf
 
Intro
IntroIntro
Intro
 
Advanced Silverlight
Advanced SilverlightAdvanced Silverlight
Advanced Silverlight
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 
Tutorial 6 queues & arrays & results recording
Tutorial 6   queues & arrays & results recording Tutorial 6   queues & arrays & results recording
Tutorial 6 queues & arrays & results recording
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
 
Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!
 
Constructor,destructors cpp
Constructor,destructors cppConstructor,destructors cpp
Constructor,destructors cpp
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Day 1
Day 1Day 1
Day 1
 
Lecture 12 os
Lecture 12 osLecture 12 os
Lecture 12 os
 
Given the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxGiven the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docx
 
iOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + GherkiniOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + Gherkin
 

More from arishaenterprises12

It was noted that excess water can kill plants. If water is not toxi.pdf
It was noted that excess water can kill plants. If water is not toxi.pdfIt was noted that excess water can kill plants. If water is not toxi.pdf
It was noted that excess water can kill plants. If water is not toxi.pdfarishaenterprises12
 
In biology, the roles of transition metal ions can be broadly groupe.pdf
In biology, the roles of transition metal ions can be broadly groupe.pdfIn biology, the roles of transition metal ions can be broadly groupe.pdf
In biology, the roles of transition metal ions can be broadly groupe.pdfarishaenterprises12
 
Image that a researcher examined how the people’s heights are associ.pdf
Image that a researcher examined how the people’s heights are associ.pdfImage that a researcher examined how the people’s heights are associ.pdf
Image that a researcher examined how the people’s heights are associ.pdfarishaenterprises12
 
I need help with this one Question 18 of 18 Sapling Learning macmill.pdf
I need help with this one Question 18 of 18 Sapling Learning macmill.pdfI need help with this one Question 18 of 18 Sapling Learning macmill.pdf
I need help with this one Question 18 of 18 Sapling Learning macmill.pdfarishaenterprises12
 
Explain how recombination increases the amount of genetic variation i.pdf
Explain how recombination increases the amount of genetic variation i.pdfExplain how recombination increases the amount of genetic variation i.pdf
Explain how recombination increases the amount of genetic variation i.pdfarishaenterprises12
 
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdfexclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdfarishaenterprises12
 
DNA is a macromolecule that is critical for life. Much of the functi.pdf
DNA is a macromolecule that is critical for life. Much of the functi.pdfDNA is a macromolecule that is critical for life. Much of the functi.pdf
DNA is a macromolecule that is critical for life. Much of the functi.pdfarishaenterprises12
 
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdfChapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdfarishaenterprises12
 
Discuss the benefits of event-driven programming.Contrast event-dr.pdf
Discuss the benefits of event-driven programming.Contrast event-dr.pdfDiscuss the benefits of event-driven programming.Contrast event-dr.pdf
Discuss the benefits of event-driven programming.Contrast event-dr.pdfarishaenterprises12
 
Before 1900, despite its weaknesses in effective management of worke.pdf
Before 1900, despite its weaknesses in effective management of worke.pdfBefore 1900, despite its weaknesses in effective management of worke.pdf
Before 1900, despite its weaknesses in effective management of worke.pdfarishaenterprises12
 
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdf
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdfAlpha particle radiation sensor. A silicon diode radiation sensor is .pdf
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdfarishaenterprises12
 
A ship was caught in a storm and driven to a small island in the mid.pdf
A ship was caught in a storm and driven to a small island in the mid.pdfA ship was caught in a storm and driven to a small island in the mid.pdf
A ship was caught in a storm and driven to a small island in the mid.pdfarishaenterprises12
 
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdfarishaenterprises12
 
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdfAs leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdfarishaenterprises12
 
Among 10 people traveling in a group, 2 have outdated passports. It .pdf
Among 10 people traveling in a group, 2 have outdated passports. It .pdfAmong 10 people traveling in a group, 2 have outdated passports. It .pdf
Among 10 people traveling in a group, 2 have outdated passports. It .pdfarishaenterprises12
 
1.) The normal eye color of Drosophila is red, but strains in which .pdf
1.) The normal eye color of Drosophila is red, but strains in which .pdf1.) The normal eye color of Drosophila is red, but strains in which .pdf
1.) The normal eye color of Drosophila is red, but strains in which .pdfarishaenterprises12
 
29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdfarishaenterprises12
 
Why does the neutralization of an acid by a base often produce water.pdf
Why does the neutralization of an acid by a base often produce water.pdfWhy does the neutralization of an acid by a base often produce water.pdf
Why does the neutralization of an acid by a base often produce water.pdfarishaenterprises12
 
Which statement about phloem transport is falseIt takes place in .pdf
Which statement about phloem transport is falseIt takes place in .pdfWhich statement about phloem transport is falseIt takes place in .pdf
Which statement about phloem transport is falseIt takes place in .pdfarishaenterprises12
 
Which of the following is not a primitive data type Which of th.pdf
Which of the following is not a primitive data type Which of th.pdfWhich of the following is not a primitive data type Which of th.pdf
Which of the following is not a primitive data type Which of th.pdfarishaenterprises12
 

More from arishaenterprises12 (20)

It was noted that excess water can kill plants. If water is not toxi.pdf
It was noted that excess water can kill plants. If water is not toxi.pdfIt was noted that excess water can kill plants. If water is not toxi.pdf
It was noted that excess water can kill plants. If water is not toxi.pdf
 
In biology, the roles of transition metal ions can be broadly groupe.pdf
In biology, the roles of transition metal ions can be broadly groupe.pdfIn biology, the roles of transition metal ions can be broadly groupe.pdf
In biology, the roles of transition metal ions can be broadly groupe.pdf
 
Image that a researcher examined how the people’s heights are associ.pdf
Image that a researcher examined how the people’s heights are associ.pdfImage that a researcher examined how the people’s heights are associ.pdf
Image that a researcher examined how the people’s heights are associ.pdf
 
I need help with this one Question 18 of 18 Sapling Learning macmill.pdf
I need help with this one Question 18 of 18 Sapling Learning macmill.pdfI need help with this one Question 18 of 18 Sapling Learning macmill.pdf
I need help with this one Question 18 of 18 Sapling Learning macmill.pdf
 
Explain how recombination increases the amount of genetic variation i.pdf
Explain how recombination increases the amount of genetic variation i.pdfExplain how recombination increases the amount of genetic variation i.pdf
Explain how recombination increases the amount of genetic variation i.pdf
 
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdfexclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
 
DNA is a macromolecule that is critical for life. Much of the functi.pdf
DNA is a macromolecule that is critical for life. Much of the functi.pdfDNA is a macromolecule that is critical for life. Much of the functi.pdf
DNA is a macromolecule that is critical for life. Much of the functi.pdf
 
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdfChapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
 
Discuss the benefits of event-driven programming.Contrast event-dr.pdf
Discuss the benefits of event-driven programming.Contrast event-dr.pdfDiscuss the benefits of event-driven programming.Contrast event-dr.pdf
Discuss the benefits of event-driven programming.Contrast event-dr.pdf
 
Before 1900, despite its weaknesses in effective management of worke.pdf
Before 1900, despite its weaknesses in effective management of worke.pdfBefore 1900, despite its weaknesses in effective management of worke.pdf
Before 1900, despite its weaknesses in effective management of worke.pdf
 
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdf
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdfAlpha particle radiation sensor. A silicon diode radiation sensor is .pdf
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdf
 
A ship was caught in a storm and driven to a small island in the mid.pdf
A ship was caught in a storm and driven to a small island in the mid.pdfA ship was caught in a storm and driven to a small island in the mid.pdf
A ship was caught in a storm and driven to a small island in the mid.pdf
 
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
 
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdfAs leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
 
Among 10 people traveling in a group, 2 have outdated passports. It .pdf
Among 10 people traveling in a group, 2 have outdated passports. It .pdfAmong 10 people traveling in a group, 2 have outdated passports. It .pdf
Among 10 people traveling in a group, 2 have outdated passports. It .pdf
 
1.) The normal eye color of Drosophila is red, but strains in which .pdf
1.) The normal eye color of Drosophila is red, but strains in which .pdf1.) The normal eye color of Drosophila is red, but strains in which .pdf
1.) The normal eye color of Drosophila is red, but strains in which .pdf
 
29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf
 
Why does the neutralization of an acid by a base often produce water.pdf
Why does the neutralization of an acid by a base often produce water.pdfWhy does the neutralization of an acid by a base often produce water.pdf
Why does the neutralization of an acid by a base often produce water.pdf
 
Which statement about phloem transport is falseIt takes place in .pdf
Which statement about phloem transport is falseIt takes place in .pdfWhich statement about phloem transport is falseIt takes place in .pdf
Which statement about phloem transport is falseIt takes place in .pdf
 
Which of the following is not a primitive data type Which of th.pdf
Which of the following is not a primitive data type Which of th.pdfWhich of the following is not a primitive data type Which of th.pdf
Which of the following is not a primitive data type Which of th.pdf
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 

Recently uploaded (20)

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 

Write the code for a small function called myStack, which creates a .pdf

  • 1. Write the code for a small function called myStack, which creates a Stack object of String elements, named cities. Add "Sydney", then "London", then "New York" and then "Beijing" to cities. Then print each element on the screen, one per line. Print each element in a way that causes cities to be empty (i.e. have 0 elements) afterwards. (6 mks) Solution PROGRAM CODE: package stack; import java.util.Stack; public class MyStackClass { //stack function public static void myStack() { //creating a stack object called cities Stack cities = new Stack(); //Adding cities into the stack cities.push("Sydney"); cities.push("London"); cities.push("New York"); cities.push("Beijing"); //using while loop to loop through the stack till its empty while(!cities.isEmpty()) { // pop function is used to remove elements from the stack // pop() returns the elemets which is printed on the csreen System.out.println(cities.pop()); } } // Main function for the class public static void main(String args[]) {
  • 2. myStack(); // function call to the stack method } } OUTPUT: Beijing New York London Sydney