SlideShare a Scribd company logo
1 of 4
Download to read offline
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x="X";
int amount;
System.out.println("Enter amount");
amount=input.nextInt();
System.out.println("Amount is: "+amount);
for(int i=1; i<=amount; i++)
{
System.out.println(x);
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Why does It print out the last set of X's twice? I am doing basic Java so please try to explain
using the most basic codes.
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x="X";
int amount;
System.out.println("Enter amount");
amount=input.nextInt();
System.out.println("Amount is: "+amount);
for(int i=1; i<=amount; i++)
{
System.out.println(x);
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Why does It print out the last set of X's twice? I am doing basic Java so please try to explain
using the most basic codes.
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x="X";
int amount;
System.out.println("Enter amount");
amount=input.nextInt();
System.out.println("Amount is: "+amount);
for(int i=1; i<=amount; i++)
{
System.out.println(x);
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Why does It print out the last set of X's twice? I am doing basic Java so please try to explain
using the most basic codes.
Solution
Hi,
I have modified the code. it is working as expected now. Highlighted the code changes below.
Issue here is with you have written this statement twice System.out.println(x); which causes the
issue.
Program.java
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x="X";
int amount;
System.out.println("Enter amount");
amount=input.nextInt();
System.out.println("Amount is: "+amount);
for(int i=1; i<=amount; i++)
{
System.out.println();
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Output:
Enter amount
10
Amount is: 10
X
XX
XXX
XXXX
XXXXX
XXXXXX
XXXXXXX
XXXXXXXX
XXXXXXXXX
XXXXXXXXXX

More Related Content

Similar to import java.util.;public class Program{public static void.pdf

Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfaquazac
 
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.pdfankkitextailes
 
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.pdfanurag1231
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfarihanthtoysandgifts
 
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.pdfanjanacottonmills
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2Ankit Gupta
 
Hello. This program has to be done in Eclipse(Program used to write .pdf
Hello. This program has to be done in Eclipse(Program used to write .pdfHello. This program has to be done in Eclipse(Program used to write .pdf
Hello. This program has to be done in Eclipse(Program used to write .pdfarchiesgallery
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfFootageetoffe16
 

Similar to import java.util.;public class Program{public static void.pdf (16)

Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.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
 
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 -lec-5
Java -lec-5Java -lec-5
Java -lec-5
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdf
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.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
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
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
 
Hello. This program has to be done in Eclipse(Program used to write .pdf
Hello. This program has to be done in Eclipse(Program used to write .pdfHello. This program has to be done in Eclipse(Program used to write .pdf
Hello. This program has to be done in Eclipse(Program used to write .pdf
 
Java programs
Java programsJava programs
Java programs
 
Programs of java
Programs of javaPrograms of java
Programs of java
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdf
 
54240326 (1)
54240326 (1)54240326 (1)
54240326 (1)
 
54240326 copy
54240326   copy54240326   copy
54240326 copy
 

More from optokunal1

Which asymmetric cryptosystem is used for digital signaturesA. DE.pdf
Which asymmetric cryptosystem is used for digital signaturesA. DE.pdfWhich asymmetric cryptosystem is used for digital signaturesA. DE.pdf
Which asymmetric cryptosystem is used for digital signaturesA. DE.pdfoptokunal1
 
Which of these theories fit into the contextual world-viewQuestio.pdf
Which of these theories fit into the contextual world-viewQuestio.pdfWhich of these theories fit into the contextual world-viewQuestio.pdf
Which of these theories fit into the contextual world-viewQuestio.pdfoptokunal1
 
Which of the following distinguishes prophase of meiosis I from proph.pdf
Which of the following distinguishes prophase of meiosis I from proph.pdfWhich of the following distinguishes prophase of meiosis I from proph.pdf
Which of the following distinguishes prophase of meiosis I from proph.pdfoptokunal1
 
What is meant by primary growth What is meant by secondary growth .pdf
What is meant by primary growth  What is meant by secondary growth .pdfWhat is meant by primary growth  What is meant by secondary growth .pdf
What is meant by primary growth What is meant by secondary growth .pdfoptokunal1
 
What to the characteristic X-ray radiation What is the originSo.pdf
What to the characteristic X-ray radiation What is the originSo.pdfWhat to the characteristic X-ray radiation What is the originSo.pdf
What to the characteristic X-ray radiation What is the originSo.pdfoptokunal1
 
What other blood cell related problems are often seen in patients wi.pdf
What other blood cell related problems are often seen in patients wi.pdfWhat other blood cell related problems are often seen in patients wi.pdf
What other blood cell related problems are often seen in patients wi.pdfoptokunal1
 
what is inductive and deductive reasoningSolutionDeductive and.pdf
what is inductive and deductive reasoningSolutionDeductive and.pdfwhat is inductive and deductive reasoningSolutionDeductive and.pdf
what is inductive and deductive reasoningSolutionDeductive and.pdfoptokunal1
 
What are the major evolutionary feats shared by all 3 phyla( Platyhe.pdf
What are the major evolutionary feats shared by all 3 phyla( Platyhe.pdfWhat are the major evolutionary feats shared by all 3 phyla( Platyhe.pdf
What are the major evolutionary feats shared by all 3 phyla( Platyhe.pdfoptokunal1
 
What are some of the advantages in the use of AOA notation as oppose.pdf
What are some of the advantages in the use of AOA notation as oppose.pdfWhat are some of the advantages in the use of AOA notation as oppose.pdf
What are some of the advantages in the use of AOA notation as oppose.pdfoptokunal1
 
Verify the identity.StartFraction sine left parenthesis alpha plus.pdf
Verify the identity.StartFraction sine left parenthesis alpha plus.pdfVerify the identity.StartFraction sine left parenthesis alpha plus.pdf
Verify the identity.StartFraction sine left parenthesis alpha plus.pdfoptokunal1
 
Use C++class Node{public   Node ( int = 0 );       constru.pdf
Use C++class Node{public   Node ( int = 0 );        constru.pdfUse C++class Node{public   Node ( int = 0 );        constru.pdf
Use C++class Node{public   Node ( int = 0 );       constru.pdfoptokunal1
 
This is a lab for a java program that I am very unsure of, it has to.pdf
This is a lab for a java program that I am very unsure of, it has to.pdfThis is a lab for a java program that I am very unsure of, it has to.pdf
This is a lab for a java program that I am very unsure of, it has to.pdfoptokunal1
 
The concentration of carbon dioxide in the atmosphere today is about .pdf
The concentration of carbon dioxide in the atmosphere today is about .pdfThe concentration of carbon dioxide in the atmosphere today is about .pdf
The concentration of carbon dioxide in the atmosphere today is about .pdfoptokunal1
 
Research and discuss two operating systems and how incident response.pdf
Research and discuss two operating systems and how incident response.pdfResearch and discuss two operating systems and how incident response.pdf
Research and discuss two operating systems and how incident response.pdfoptokunal1
 
Proteins can be attached to a membrane in a variety of ways. How doe.pdf
Proteins can be attached to a membrane in a variety of ways. How doe.pdfProteins can be attached to a membrane in a variety of ways. How doe.pdf
Proteins can be attached to a membrane in a variety of ways. How doe.pdfoptokunal1
 
Problem 1-What is environmental engineering (20 pts) Below you wil.pdf
Problem 1-What is environmental engineering (20 pts) Below you wil.pdfProblem 1-What is environmental engineering (20 pts) Below you wil.pdf
Problem 1-What is environmental engineering (20 pts) Below you wil.pdfoptokunal1
 
NetWork Design Question2.) How does TCP prevent Congestion Dicuss.pdf
NetWork Design Question2.) How does TCP prevent Congestion Dicuss.pdfNetWork Design Question2.) How does TCP prevent Congestion Dicuss.pdf
NetWork Design Question2.) How does TCP prevent Congestion Dicuss.pdfoptokunal1
 
Mosses and liverworts are early colonizers during ecological success.pdf
Mosses and liverworts are early colonizers during ecological success.pdfMosses and liverworts are early colonizers during ecological success.pdf
Mosses and liverworts are early colonizers during ecological success.pdfoptokunal1
 
Many programming languages, especially older ones, provide no langua.pdf
Many programming languages, especially older ones, provide no langua.pdfMany programming languages, especially older ones, provide no langua.pdf
Many programming languages, especially older ones, provide no langua.pdfoptokunal1
 
Inferior nasal concha Lacrimal bone Mandible Maxilla Nasal bone .pdf
Inferior nasal concha  Lacrimal bone  Mandible  Maxilla  Nasal bone  .pdfInferior nasal concha  Lacrimal bone  Mandible  Maxilla  Nasal bone  .pdf
Inferior nasal concha Lacrimal bone Mandible Maxilla Nasal bone .pdfoptokunal1
 

More from optokunal1 (20)

Which asymmetric cryptosystem is used for digital signaturesA. DE.pdf
Which asymmetric cryptosystem is used for digital signaturesA. DE.pdfWhich asymmetric cryptosystem is used for digital signaturesA. DE.pdf
Which asymmetric cryptosystem is used for digital signaturesA. DE.pdf
 
Which of these theories fit into the contextual world-viewQuestio.pdf
Which of these theories fit into the contextual world-viewQuestio.pdfWhich of these theories fit into the contextual world-viewQuestio.pdf
Which of these theories fit into the contextual world-viewQuestio.pdf
 
Which of the following distinguishes prophase of meiosis I from proph.pdf
Which of the following distinguishes prophase of meiosis I from proph.pdfWhich of the following distinguishes prophase of meiosis I from proph.pdf
Which of the following distinguishes prophase of meiosis I from proph.pdf
 
What is meant by primary growth What is meant by secondary growth .pdf
What is meant by primary growth  What is meant by secondary growth .pdfWhat is meant by primary growth  What is meant by secondary growth .pdf
What is meant by primary growth What is meant by secondary growth .pdf
 
What to the characteristic X-ray radiation What is the originSo.pdf
What to the characteristic X-ray radiation What is the originSo.pdfWhat to the characteristic X-ray radiation What is the originSo.pdf
What to the characteristic X-ray radiation What is the originSo.pdf
 
What other blood cell related problems are often seen in patients wi.pdf
What other blood cell related problems are often seen in patients wi.pdfWhat other blood cell related problems are often seen in patients wi.pdf
What other blood cell related problems are often seen in patients wi.pdf
 
what is inductive and deductive reasoningSolutionDeductive and.pdf
what is inductive and deductive reasoningSolutionDeductive and.pdfwhat is inductive and deductive reasoningSolutionDeductive and.pdf
what is inductive and deductive reasoningSolutionDeductive and.pdf
 
What are the major evolutionary feats shared by all 3 phyla( Platyhe.pdf
What are the major evolutionary feats shared by all 3 phyla( Platyhe.pdfWhat are the major evolutionary feats shared by all 3 phyla( Platyhe.pdf
What are the major evolutionary feats shared by all 3 phyla( Platyhe.pdf
 
What are some of the advantages in the use of AOA notation as oppose.pdf
What are some of the advantages in the use of AOA notation as oppose.pdfWhat are some of the advantages in the use of AOA notation as oppose.pdf
What are some of the advantages in the use of AOA notation as oppose.pdf
 
Verify the identity.StartFraction sine left parenthesis alpha plus.pdf
Verify the identity.StartFraction sine left parenthesis alpha plus.pdfVerify the identity.StartFraction sine left parenthesis alpha plus.pdf
Verify the identity.StartFraction sine left parenthesis alpha plus.pdf
 
Use C++class Node{public   Node ( int = 0 );       constru.pdf
Use C++class Node{public   Node ( int = 0 );        constru.pdfUse C++class Node{public   Node ( int = 0 );        constru.pdf
Use C++class Node{public   Node ( int = 0 );       constru.pdf
 
This is a lab for a java program that I am very unsure of, it has to.pdf
This is a lab for a java program that I am very unsure of, it has to.pdfThis is a lab for a java program that I am very unsure of, it has to.pdf
This is a lab for a java program that I am very unsure of, it has to.pdf
 
The concentration of carbon dioxide in the atmosphere today is about .pdf
The concentration of carbon dioxide in the atmosphere today is about .pdfThe concentration of carbon dioxide in the atmosphere today is about .pdf
The concentration of carbon dioxide in the atmosphere today is about .pdf
 
Research and discuss two operating systems and how incident response.pdf
Research and discuss two operating systems and how incident response.pdfResearch and discuss two operating systems and how incident response.pdf
Research and discuss two operating systems and how incident response.pdf
 
Proteins can be attached to a membrane in a variety of ways. How doe.pdf
Proteins can be attached to a membrane in a variety of ways. How doe.pdfProteins can be attached to a membrane in a variety of ways. How doe.pdf
Proteins can be attached to a membrane in a variety of ways. How doe.pdf
 
Problem 1-What is environmental engineering (20 pts) Below you wil.pdf
Problem 1-What is environmental engineering (20 pts) Below you wil.pdfProblem 1-What is environmental engineering (20 pts) Below you wil.pdf
Problem 1-What is environmental engineering (20 pts) Below you wil.pdf
 
NetWork Design Question2.) How does TCP prevent Congestion Dicuss.pdf
NetWork Design Question2.) How does TCP prevent Congestion Dicuss.pdfNetWork Design Question2.) How does TCP prevent Congestion Dicuss.pdf
NetWork Design Question2.) How does TCP prevent Congestion Dicuss.pdf
 
Mosses and liverworts are early colonizers during ecological success.pdf
Mosses and liverworts are early colonizers during ecological success.pdfMosses and liverworts are early colonizers during ecological success.pdf
Mosses and liverworts are early colonizers during ecological success.pdf
 
Many programming languages, especially older ones, provide no langua.pdf
Many programming languages, especially older ones, provide no langua.pdfMany programming languages, especially older ones, provide no langua.pdf
Many programming languages, especially older ones, provide no langua.pdf
 
Inferior nasal concha Lacrimal bone Mandible Maxilla Nasal bone .pdf
Inferior nasal concha  Lacrimal bone  Mandible  Maxilla  Nasal bone  .pdfInferior nasal concha  Lacrimal bone  Mandible  Maxilla  Nasal bone  .pdf
Inferior nasal concha Lacrimal bone Mandible Maxilla Nasal bone .pdf
 

Recently uploaded

History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

import java.util.;public class Program{public static void.pdf

  • 1. import java.util.*; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); String x="X"; int amount; System.out.println("Enter amount"); amount=input.nextInt(); System.out.println("Amount is: "+amount); for(int i=1; i<=amount; i++) { System.out.println(x); for(int j=1; j<=i; j++) { System.out.print(x); } } } } Why does It print out the last set of X's twice? I am doing basic Java so please try to explain using the most basic codes. import java.util.*; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); String x="X";
  • 2. int amount; System.out.println("Enter amount"); amount=input.nextInt(); System.out.println("Amount is: "+amount); for(int i=1; i<=amount; i++) { System.out.println(x); for(int j=1; j<=i; j++) { System.out.print(x); } } } } Why does It print out the last set of X's twice? I am doing basic Java so please try to explain using the most basic codes. import java.util.*; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); String x="X"; int amount; System.out.println("Enter amount"); amount=input.nextInt(); System.out.println("Amount is: "+amount); for(int i=1; i<=amount; i++) { System.out.println(x); for(int j=1; j<=i; j++) { System.out.print(x);
  • 3. } } } } Why does It print out the last set of X's twice? I am doing basic Java so please try to explain using the most basic codes. Solution Hi, I have modified the code. it is working as expected now. Highlighted the code changes below. Issue here is with you have written this statement twice System.out.println(x); which causes the issue. Program.java import java.util.*; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); String x="X"; int amount; System.out.println("Enter amount"); amount=input.nextInt(); System.out.println("Amount is: "+amount); for(int i=1; i<=amount; i++) { System.out.println();
  • 4. for(int j=1; j<=i; j++) { System.out.print(x); } } } } Output: Enter amount 10 Amount is: 10 X XX XXX XXXX XXXXX XXXXXX XXXXXXX XXXXXXXX XXXXXXXXX XXXXXXXXXX