SlideShare a Scribd company logo
1 of 1
Download to read offline
Using NetBeans
Q1. Write a program that uses a stack to convert a number in base 10 to a number in base 2.
Solution
import java.util.Scanner;
public class Decimal2BinaryDemo {
public static void main(String args[]) {
Scanner in =new Scanner(System.in);
System.out.println("Enter decimal number =");
int num=in.nextInt();
Stack s4 = new Stack();
int n=num;
int i = 0;
while (n > 0) {
s4.push(n % 2);
n = n / 2;
i++;
}
//s4.print();
System.out.print(num+" is convert to binary ->");
while (i > 0) {
System.out.print(s4.pop()+" ");
i--;
}
}
}

More Related Content

More from callawaycorb73779

describe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdfdescribe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdfcallawaycorb73779
 
Compare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdfCompare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdfcallawaycorb73779
 
Chemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdfChemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdfcallawaycorb73779
 
An adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdfAn adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdfcallawaycorb73779
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
 
1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdf1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdfcallawaycorb73779
 
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdfYou have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdfcallawaycorb73779
 
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdfYou have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdfcallawaycorb73779
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfcallawaycorb73779
 
Which one of the following statements about lichens is false lichen.pdf
Which one of the following statements about lichens is false  lichen.pdfWhich one of the following statements about lichens is false  lichen.pdf
Which one of the following statements about lichens is false lichen.pdfcallawaycorb73779
 
What is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdfWhat is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdfcallawaycorb73779
 
What are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdfWhat are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdfcallawaycorb73779
 
Use the counting techniques from the last chapter. A bag contains fo.pdf
Use the counting techniques from the last chapter. A bag contains fo.pdfUse the counting techniques from the last chapter. A bag contains fo.pdf
Use the counting techniques from the last chapter. A bag contains fo.pdfcallawaycorb73779
 
the three types of associations (chance, non-causal, and causal). De.pdf
the three types of associations (chance, non-causal, and causal). De.pdfthe three types of associations (chance, non-causal, and causal). De.pdf
the three types of associations (chance, non-causal, and causal). De.pdfcallawaycorb73779
 
The problem of so-called “push polls”When advocacy calls are made .pdf
The problem of so-called “push polls”When advocacy calls are made .pdfThe problem of so-called “push polls”When advocacy calls are made .pdf
The problem of so-called “push polls”When advocacy calls are made .pdfcallawaycorb73779
 
The phylogeny in this figure shows the evolution of visual opsins in .pdf
The phylogeny in this figure shows the evolution of visual opsins in .pdfThe phylogeny in this figure shows the evolution of visual opsins in .pdf
The phylogeny in this figure shows the evolution of visual opsins in .pdfcallawaycorb73779
 
The hypothetical Western Chickadee comprises three major populations.pdf
The hypothetical Western Chickadee comprises three major populations.pdfThe hypothetical Western Chickadee comprises three major populations.pdf
The hypothetical Western Chickadee comprises three major populations.pdfcallawaycorb73779
 
The accumulation of partially decayed plant material is called Pea Pe.pdf
The accumulation of partially decayed plant material is called Pea Pe.pdfThe accumulation of partially decayed plant material is called Pea Pe.pdf
The accumulation of partially decayed plant material is called Pea Pe.pdfcallawaycorb73779
 
19. DNA “Nucleotide bases” are selective in their bonding. Thinking .pdf
19. DNA “Nucleotide bases” are selective in their bonding. Thinking .pdf19. DNA “Nucleotide bases” are selective in their bonding. Thinking .pdf
19. DNA “Nucleotide bases” are selective in their bonding. Thinking .pdfcallawaycorb73779
 
Suppose that you and I are friends on Facebook. and you want to figur.pdf
Suppose that you and I are friends on Facebook. and you want to figur.pdfSuppose that you and I are friends on Facebook. and you want to figur.pdf
Suppose that you and I are friends on Facebook. and you want to figur.pdfcallawaycorb73779
 

More from callawaycorb73779 (20)

describe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdfdescribe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdf
 
Compare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdfCompare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdf
 
Chemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdfChemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdf
 
An adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdfAn adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdf1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdf
 
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdfYou have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
 
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdfYou have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdf
 
Which one of the following statements about lichens is false lichen.pdf
Which one of the following statements about lichens is false  lichen.pdfWhich one of the following statements about lichens is false  lichen.pdf
Which one of the following statements about lichens is false lichen.pdf
 
What is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdfWhat is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdf
 
What are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdfWhat are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdf
 
Use the counting techniques from the last chapter. A bag contains fo.pdf
Use the counting techniques from the last chapter. A bag contains fo.pdfUse the counting techniques from the last chapter. A bag contains fo.pdf
Use the counting techniques from the last chapter. A bag contains fo.pdf
 
the three types of associations (chance, non-causal, and causal). De.pdf
the three types of associations (chance, non-causal, and causal). De.pdfthe three types of associations (chance, non-causal, and causal). De.pdf
the three types of associations (chance, non-causal, and causal). De.pdf
 
The problem of so-called “push polls”When advocacy calls are made .pdf
The problem of so-called “push polls”When advocacy calls are made .pdfThe problem of so-called “push polls”When advocacy calls are made .pdf
The problem of so-called “push polls”When advocacy calls are made .pdf
 
The phylogeny in this figure shows the evolution of visual opsins in .pdf
The phylogeny in this figure shows the evolution of visual opsins in .pdfThe phylogeny in this figure shows the evolution of visual opsins in .pdf
The phylogeny in this figure shows the evolution of visual opsins in .pdf
 
The hypothetical Western Chickadee comprises three major populations.pdf
The hypothetical Western Chickadee comprises three major populations.pdfThe hypothetical Western Chickadee comprises three major populations.pdf
The hypothetical Western Chickadee comprises three major populations.pdf
 
The accumulation of partially decayed plant material is called Pea Pe.pdf
The accumulation of partially decayed plant material is called Pea Pe.pdfThe accumulation of partially decayed plant material is called Pea Pe.pdf
The accumulation of partially decayed plant material is called Pea Pe.pdf
 
19. DNA “Nucleotide bases” are selective in their bonding. Thinking .pdf
19. DNA “Nucleotide bases” are selective in their bonding. Thinking .pdf19. DNA “Nucleotide bases” are selective in their bonding. Thinking .pdf
19. DNA “Nucleotide bases” are selective in their bonding. Thinking .pdf
 
Suppose that you and I are friends on Facebook. and you want to figur.pdf
Suppose that you and I are friends on Facebook. and you want to figur.pdfSuppose that you and I are friends on Facebook. and you want to figur.pdf
Suppose that you and I are friends on Facebook. and you want to figur.pdf
 

Recently uploaded

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
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
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
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
 
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
 
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
 
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
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Recently uploaded (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
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
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.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
 
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.
 
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Ă...
 
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...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Using NetBeansQ1. Write a program that uses a stack to convert a n.pdf

  • 1. Using NetBeans Q1. Write a program that uses a stack to convert a number in base 10 to a number in base 2. Solution import java.util.Scanner; public class Decimal2BinaryDemo { public static void main(String args[]) { Scanner in =new Scanner(System.in); System.out.println("Enter decimal number ="); int num=in.nextInt(); Stack s4 = new Stack(); int n=num; int i = 0; while (n > 0) { s4.push(n % 2); n = n / 2; i++; } //s4.print(); System.out.print(num+" is convert to binary ->"); while (i > 0) { System.out.print(s4.pop()+" "); i--; } } }