SlideShare a Scribd company logo
1 of 2
Download to read offline
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:

More Related Content

Similar to 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 to 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
 

More from 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
 

More from 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
 

Recently uploaded

IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
17thcssbs2
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 

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: