SlideShare una empresa de Scribd logo
1 de 2
Below is a program that takes an integer as input. Write a for loop which prints a countdown
from that number till 1 eg: if the inputted number is 4, then output should be: 4 3 2 1 Notes: 1.
Use only for loop 2. Write your code only inside the placeholders provided. Do not edit the
remaining part of the code.
-------------------------------
import java.util.Scanner;
class countdown{
public static void main(String args[]){
int startNum;
Scanner scanner =new Scanner(System.in);
System.out.println("Enter the number:");
startNum=scanner.nextInt();
///{
///}
}
}
Solution
Answer
import java.util.Scanner;
class countdown
{
public static void main(String args[])
{
int startNum;
Scanner scanner =new Scanner(System.in);
System.out.println("Enter the number:");
startNum=scanner.nextInt();
for(int i=startNum;i>0;i--) //for loop starts from number entered
{
System.out.println(i); //prints the value of i
}
}
}

Más contenido relacionado

Similar a Below is a program that takes an integer as input- Write a for loop wh.docx

Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdfQ1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
fathimalinks
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
optokunal1
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
Aiman Hud
 

Similar a Below is a program that takes an integer as input- Write a for loop wh.docx (9)

C#.net
C#.netC#.net
C#.net
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdf
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdfQ1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
Java final lab
Java final labJava final lab
Java final lab
 

Más de danielt47

Black Holes are cores of dying stars that have gravitationally collaps.docx
Black Holes are cores of dying stars that have gravitationally collaps.docxBlack Holes are cores of dying stars that have gravitationally collaps.docx
Black Holes are cores of dying stars that have gravitationally collaps.docx
danielt47
 
Based on the information in Atom- Clash of the Titans- please answer t.docx
Based on the information in Atom- Clash of the Titans- please answer t.docxBased on the information in Atom- Clash of the Titans- please answer t.docx
Based on the information in Atom- Clash of the Titans- please answer t.docx
danielt47
 
Boston Scientific faced the challenge of balancing openness and sharin.docx
Boston Scientific faced the challenge of balancing openness and sharin.docxBoston Scientific faced the challenge of balancing openness and sharin.docx
Boston Scientific faced the challenge of balancing openness and sharin.docx
danielt47
 

Más de danielt47 (20)

Bob Company has the following balances on January 31- 2013- Cash $800.docx
Bob Company has the following balances on January 31- 2013-  Cash $800.docxBob Company has the following balances on January 31- 2013-  Cash $800.docx
Bob Company has the following balances on January 31- 2013- Cash $800.docx
 
Bob the scientist has a 100 mL solutin that contains 0-03 moles of eac.docx
Bob the scientist has a 100 mL solutin that contains 0-03 moles of eac.docxBob the scientist has a 100 mL solutin that contains 0-03 moles of eac.docx
Bob the scientist has a 100 mL solutin that contains 0-03 moles of eac.docx
 
Blanche Blanche SolutionJournal Entry to record Requisition of.docx
Blanche     Blanche    SolutionJournal Entry to record Requisition of.docxBlanche     Blanche    SolutionJournal Entry to record Requisition of.docx
Blanche Blanche SolutionJournal Entry to record Requisition of.docx
 
Blanton Corporation purchased 12- of the outstanding shares of common.docx
Blanton Corporation purchased 12- of the outstanding shares of common.docxBlanton Corporation purchased 12- of the outstanding shares of common.docx
Blanton Corporation purchased 12- of the outstanding shares of common.docx
 
Black Holes are cores of dying stars that have gravitationally collaps.docx
Black Holes are cores of dying stars that have gravitationally collaps.docxBlack Holes are cores of dying stars that have gravitationally collaps.docx
Black Holes are cores of dying stars that have gravitationally collaps.docx
 
Beyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxBeyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docx
 
Beside the typical DBMS- what are some of the different data sources t.docx
Beside the typical DBMS- what are some of the different data sources t.docxBeside the typical DBMS- what are some of the different data sources t.docx
Beside the typical DBMS- what are some of the different data sources t.docx
 
Below are three independent and unrelated accounting errors- For each.docx
Below are three independent and unrelated accounting errors- For each.docxBelow are three independent and unrelated accounting errors- For each.docx
Below are three independent and unrelated accounting errors- For each.docx
 
Be sure to answer all parts- Give the Mino acid sequence of an octapep.docx
Be sure to answer all parts- Give the Mino acid sequence of an octapep.docxBe sure to answer all parts- Give the Mino acid sequence of an octapep.docx
Be sure to answer all parts- Give the Mino acid sequence of an octapep.docx
 
Basic naming lab Name Naming Lab Report In lieu of a lab report- pleas.docx
Basic naming lab Name Naming Lab Report In lieu of a lab report- pleas.docxBasic naming lab Name Naming Lab Report In lieu of a lab report- pleas.docx
Basic naming lab Name Naming Lab Report In lieu of a lab report- pleas.docx
 
Based on the information in Atom- Clash of the Titans- please answer t.docx
Based on the information in Atom- Clash of the Titans- please answer t.docxBased on the information in Atom- Clash of the Titans- please answer t.docx
Based on the information in Atom- Clash of the Titans- please answer t.docx
 
Both these questions go togetherSolutionWhen we bring a magnet near a.docx
Both these questions go togetherSolutionWhen we bring a magnet near a.docxBoth these questions go togetherSolutionWhen we bring a magnet near a.docx
Both these questions go togetherSolutionWhen we bring a magnet near a.docx
 
Boston Scientific faced the challenge of balancing openness and sharin.docx
Boston Scientific faced the challenge of balancing openness and sharin.docxBoston Scientific faced the challenge of balancing openness and sharin.docx
Boston Scientific faced the challenge of balancing openness and sharin.docx
 
Based on the information in Atom- Clash of the Titans- please answer t (2).docx
Based on the information in Atom- Clash of the Titans- please answer t (2).docxBased on the information in Atom- Clash of the Titans- please answer t (2).docx
Based on the information in Atom- Clash of the Titans- please answer t (2).docx
 
6-3- (a) In which form does Cd(II) occur mainly in a water of the foll.docx
6-3- (a) In which form does Cd(II) occur mainly in a water of the foll.docx6-3- (a) In which form does Cd(II) occur mainly in a water of the foll.docx
6-3- (a) In which form does Cd(II) occur mainly in a water of the foll.docx
 
6- A solution of an acid- with a general formula HA- contains 0-400 mo.docx
6- A solution of an acid- with a general formula HA- contains 0-400 mo.docx6- A solution of an acid- with a general formula HA- contains 0-400 mo.docx
6- A solution of an acid- with a general formula HA- contains 0-400 mo.docx
 
6- What are the differences between objects and abstract data typesSol.docx
6- What are the differences between objects and abstract data typesSol.docx6- What are the differences between objects and abstract data typesSol.docx
6- What are the differences between objects and abstract data typesSol.docx
 
6- What do the bubbles in boiling water principally c a- air b- O2 (e.docx
6- What do the bubbles in boiling water principally c a- air b- O2 (e.docx6- What do the bubbles in boiling water principally c a- air b- O2 (e.docx
6- What do the bubbles in boiling water principally c a- air b- O2 (e.docx
 
6- Both solutions and colloids are mixtures- Differentiate between the.docx
6- Both solutions and colloids are mixtures- Differentiate between the.docx6- Both solutions and colloids are mixtures- Differentiate between the.docx
6- Both solutions and colloids are mixtures- Differentiate between the.docx
 
6)- The Town of Elmwood applied for a competitive grant from the state.docx
6)- The Town of Elmwood applied for a competitive grant from the state.docx6)- The Town of Elmwood applied for a competitive grant from the state.docx
6)- The Town of Elmwood applied for a competitive grant from the state.docx
 

Último

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Below is a program that takes an integer as input- Write a for loop wh.docx

  • 1. Below is a program that takes an integer as input. Write a for loop which prints a countdown from that number till 1 eg: if the inputted number is 4, then output should be: 4 3 2 1 Notes: 1. Use only for loop 2. Write your code only inside the placeholders provided. Do not edit the remaining part of the code. ------------------------------- import java.util.Scanner; class countdown{ public static void main(String args[]){ int startNum; Scanner scanner =new Scanner(System.in); System.out.println("Enter the number:"); startNum=scanner.nextInt(); ///{ ///} } } Solution Answer import java.util.Scanner; class countdown { public static void main(String args[]) {
  • 2. int startNum; Scanner scanner =new Scanner(System.in); System.out.println("Enter the number:"); startNum=scanner.nextInt(); for(int i=startNum;i>0;i--) //for loop starts from number entered { System.out.println(i); //prints the value of i } } }