SlideShare una empresa de Scribd logo
1 de 2
Descargar para leer sin conexión
Here is the code for you:
import java.util.*;
class PrintNumberWithCommas
{
public static void main(String[] args)
{
int number;
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer between 1000 and 999999: ");
number = sc.nextInt();
while(number < 1000 || number > 999999)
{
System.out.println("Invalid input. Retry...");
System.out.print("Enter an integer between 1000 and 999999: ");
number = sc.nextInt();
}
String output = Integer.toString(number);
output = output.substring(0, output.length() - 3) + "," + output.substring(output.length() - 3);
System.out.println(output);
}
}
And the output screenshot is:
Solution
Here is the code for you:
import java.util.*;
class PrintNumberWithCommas
{
public static void main(String[] args)
{
int number;
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer between 1000 and 999999: ");
number = sc.nextInt();
while(number < 1000 || number > 999999)
{
System.out.println("Invalid input. Retry...");
System.out.print("Enter an integer between 1000 and 999999: ");
number = sc.nextInt();
}
String output = Integer.toString(number);
output = output.substring(0, output.length() - 3) + "," + output.substring(output.length() - 3);
System.out.println(output);
}
}
And the output screenshot is:

Más contenido relacionado

Similar a Here is the code for youimport java.util.; class PrintNumberWi.pdf

import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
angelsfashion1
 
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
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
anupamfootwear
 

Similar a Here is the code for youimport java.util.; class PrintNumberWi.pdf (10)

Java -lec-5
Java -lec-5Java -lec-5
Java -lec-5
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
 
Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
 
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
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
Oot practical
Oot practicalOot practical
Oot practical
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfSumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
 

Más de anjalikatrust

      In the gravimetric method forthe determinationof Sulphate ion .pdf
      In the gravimetric method forthe determinationof Sulphate ion .pdf      In the gravimetric method forthe determinationof Sulphate ion .pdf
      In the gravimetric method forthe determinationof Sulphate ion .pdf
anjalikatrust
 
The DNA replication occurs through the coordinated sequences of init.pdf
The DNA replication occurs through the coordinated sequences of init.pdfThe DNA replication occurs through the coordinated sequences of init.pdf
The DNA replication occurs through the coordinated sequences of init.pdf
anjalikatrust
 
Suppose there exists a function called Insert designed to insert a v.pdf
Suppose there exists a function called Insert designed to insert a v.pdfSuppose there exists a function called Insert designed to insert a v.pdf
Suppose there exists a function called Insert designed to insert a v.pdf
anjalikatrust
 
Rules-based accounting is basically a list of detailed rules that mu.pdf
Rules-based accounting is basically a list of detailed rules that mu.pdfRules-based accounting is basically a list of detailed rules that mu.pdf
Rules-based accounting is basically a list of detailed rules that mu.pdf
anjalikatrust
 
Legionellosis is caused by the bacterium Legionella pneumophila. The.pdf
Legionellosis is caused by the bacterium Legionella pneumophila. The.pdfLegionellosis is caused by the bacterium Legionella pneumophila. The.pdf
Legionellosis is caused by the bacterium Legionella pneumophila. The.pdf
anjalikatrust
 
It is extreme important for a firm to able to meet its obligation as.pdf
It is extreme important for a firm to able to meet its obligation as.pdfIt is extreme important for a firm to able to meet its obligation as.pdf
It is extreme important for a firm to able to meet its obligation as.pdf
anjalikatrust
 

Más de anjalikatrust (20)

no reaction between them. Solution .pdf
                     no reaction between them.  Solution          .pdf                     no reaction between them.  Solution          .pdf
no reaction between them. Solution .pdf
 
True ; examples are CO2 ,SO2 .pdf
                     True  ; examples are CO2 ,SO2                    .pdf                     True  ; examples are CO2 ,SO2                    .pdf
True ; examples are CO2 ,SO2 .pdf
 
Groups III (Al, Ga, In, Tl), Group IV (GE, Sn and.pdf
                     Groups III (Al, Ga, In, Tl), Group IV (GE, Sn and.pdf                     Groups III (Al, Ga, In, Tl), Group IV (GE, Sn and.pdf
Groups III (Al, Ga, In, Tl), Group IV (GE, Sn and.pdf
 
·Solution·.pdf
·Solution·.pdf·Solution·.pdf
·Solution·.pdf
 
      In the gravimetric method forthe determinationof Sulphate ion .pdf
      In the gravimetric method forthe determinationof Sulphate ion .pdf      In the gravimetric method forthe determinationof Sulphate ion .pdf
      In the gravimetric method forthe determinationof Sulphate ion .pdf
 
Ecell= Eocell + 0.059n (Log(k)) using this equa.pdf
                     Ecell= Eocell + 0.059n (Log(k))  using this equa.pdf                     Ecell= Eocell + 0.059n (Log(k))  using this equa.pdf
Ecell= Eocell + 0.059n (Log(k)) using this equa.pdf
 
The DNA replication occurs through the coordinated sequences of init.pdf
The DNA replication occurs through the coordinated sequences of init.pdfThe DNA replication occurs through the coordinated sequences of init.pdf
The DNA replication occurs through the coordinated sequences of init.pdf
 
Suppose there exists a function called Insert designed to insert a v.pdf
Suppose there exists a function called Insert designed to insert a v.pdfSuppose there exists a function called Insert designed to insert a v.pdf
Suppose there exists a function called Insert designed to insert a v.pdf
 
Rules-based accounting is basically a list of detailed rules that mu.pdf
Rules-based accounting is basically a list of detailed rules that mu.pdfRules-based accounting is basically a list of detailed rules that mu.pdf
Rules-based accounting is basically a list of detailed rules that mu.pdf
 
Condensation of steam, because its just a phase.pdf
                     Condensation of steam, because its just a phase.pdf                     Condensation of steam, because its just a phase.pdf
Condensation of steam, because its just a phase.pdf
 
Please rate - ThanksD) The beta-anomer of the furanose form of a.pdf
Please rate - ThanksD) The beta-anomer of the furanose form of a.pdfPlease rate - ThanksD) The beta-anomer of the furanose form of a.pdf
Please rate - ThanksD) The beta-anomer of the furanose form of a.pdf
 
B. Alcohols are capable of acting as acids as a.pdf
                     B. Alcohols are capable of acting as acids   as a.pdf                     B. Alcohols are capable of acting as acids   as a.pdf
B. Alcohols are capable of acting as acids as a.pdf
 
Legionellosis is caused by the bacterium Legionella pneumophila. The.pdf
Legionellosis is caused by the bacterium Legionella pneumophila. The.pdfLegionellosis is caused by the bacterium Legionella pneumophila. The.pdf
Legionellosis is caused by the bacterium Legionella pneumophila. The.pdf
 
It is extreme important for a firm to able to meet its obligation as.pdf
It is extreme important for a firm to able to meet its obligation as.pdfIt is extreme important for a firm to able to meet its obligation as.pdf
It is extreme important for a firm to able to meet its obligation as.pdf
 
This is a decomposition reaction. Notes (1)combu.pdf
                     This is a decomposition reaction. Notes (1)combu.pdf                     This is a decomposition reaction. Notes (1)combu.pdf
This is a decomposition reaction. Notes (1)combu.pdf
 
sp sp2 .pdf
                     sp  sp2                                      .pdf                     sp  sp2                                      .pdf
sp sp2 .pdf
 
Given that [H+ ] = 2.2x10 -7 MWe know that [H+ ] [ OH- ] = Kw ( io.pdf
Given that [H+ ] = 2.2x10 -7 MWe know that [H+ ] [ OH- ] = Kw ( io.pdfGiven that [H+ ] = 2.2x10 -7 MWe know that [H+ ] [ OH- ] = Kw ( io.pdf
Given that [H+ ] = 2.2x10 -7 MWe know that [H+ ] [ OH- ] = Kw ( io.pdf
 
Graphite is carbon in the form of hexagonal crystalline layers, in w.pdf
Graphite is carbon in the form of hexagonal crystalline layers, in w.pdfGraphite is carbon in the form of hexagonal crystalline layers, in w.pdf
Graphite is carbon in the form of hexagonal crystalline layers, in w.pdf
 
During fermentation, when O2 is not present, NAD+ is regenerated fro.pdf
During fermentation, when O2 is not present, NAD+ is regenerated fro.pdfDuring fermentation, when O2 is not present, NAD+ is regenerated fro.pdf
During fermentation, when O2 is not present, NAD+ is regenerated fro.pdf
 
Ellipse locus of points which moves such that sum of the distances.pdf
Ellipse  locus of points which moves such that sum of the distances.pdfEllipse  locus of points which moves such that sum of the distances.pdf
Ellipse locus of points which moves such that sum of the distances.pdf
 

Último

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
KarakKing
 
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
 

Último (20)

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
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
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
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
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
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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...
 
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
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
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.
 
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
 
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...
 

Here is the code for youimport java.util.; class PrintNumberWi.pdf

  • 1. Here is the code for you: import java.util.*; class PrintNumberWithCommas { public static void main(String[] args) { int number; Scanner sc = new Scanner(System.in); System.out.print("Enter an integer between 1000 and 999999: "); number = sc.nextInt(); while(number < 1000 || number > 999999) { System.out.println("Invalid input. Retry..."); System.out.print("Enter an integer between 1000 and 999999: "); number = sc.nextInt(); } String output = Integer.toString(number); output = output.substring(0, output.length() - 3) + "," + output.substring(output.length() - 3); System.out.println(output); } } And the output screenshot is: Solution Here is the code for you: import java.util.*; class PrintNumberWithCommas { public static void main(String[] args) { int number; Scanner sc = new Scanner(System.in); System.out.print("Enter an integer between 1000 and 999999: "); number = sc.nextInt();
  • 2. while(number < 1000 || number > 999999) { System.out.println("Invalid input. Retry..."); System.out.print("Enter an integer between 1000 and 999999: "); number = sc.nextInt(); } String output = Integer.toString(number); output = output.substring(0, output.length() - 3) + "," + output.substring(output.length() - 3); System.out.println(output); } } And the output screenshot is: