SlideShare une entreprise Scribd logo
1  sur  3
Open the provided file
ConvertLoop.java
Convert the following code so that it uses nested while statements instead of for
statements. Place the new code at the end of the code in
ConvertLoop.java
.
You can
reuse the same variables, but be sure to initialize num1
back to 0 and
num2
back to 1.
int num1
= 0;
int num2
= 1;
for (int i = 0; i < 5; i++)
{
num1
= num1
+ i;
for (int j = i; j > 0; j--)
{
num2
= num2
+ (j-
1);
}
num1
= num1
+ num2;
System.
out
.println("T is " + num2);
}
System.
out
.println("S is " + num1);
Solution
I have converted the code in while loop. I hope this would help you.
int num1=0;
while(num1<5)
{
num= num1++;
int num2=1;
while(num2>=num1)
{
num2 = num2--;
}
System.out.println(“T is―, +num2);
}
System.out.println(“S is―, +num1);

Contenu connexe

Plus de lmark1

The case notes that Nationwide had in mind a simple goal- but faced a.docx
The case notes that Nationwide had in mind a simple goal- but faced a.docxThe case notes that Nationwide had in mind a simple goal- but faced a.docx
The case notes that Nationwide had in mind a simple goal- but faced a.docxlmark1
 
The capital budgeting analytical technique that calculates the rate of.docx
The capital budgeting analytical technique that calculates the rate of.docxThe capital budgeting analytical technique that calculates the rate of.docx
The capital budgeting analytical technique that calculates the rate of.docxlmark1
 
The balance sheet is the cornerstone of the financial statements- The.docx
The balance sheet is the cornerstone of the financial statements- The.docxThe balance sheet is the cornerstone of the financial statements- The.docx
The balance sheet is the cornerstone of the financial statements- The.docxlmark1
 
The capital account balances for Donald & Hanes LLP on January 1- 2011.docx
The capital account balances for Donald & Hanes LLP on January 1- 2011.docxThe capital account balances for Donald & Hanes LLP on January 1- 2011.docx
The capital account balances for Donald & Hanes LLP on January 1- 2011.docxlmark1
 
the bookkeeper of vitial inc has asked to assist him with preparation.docx
the bookkeeper of vitial inc has asked to assist him with preparation.docxthe bookkeeper of vitial inc has asked to assist him with preparation.docx
the bookkeeper of vitial inc has asked to assist him with preparation.docxlmark1
 
The balanced scorecard integrates financial and nonfinancial measures.docx
The balanced scorecard integrates financial and nonfinancial measures.docxThe balanced scorecard integrates financial and nonfinancial measures.docx
The balanced scorecard integrates financial and nonfinancial measures.docxlmark1
 
The balance sheet for the partnership of Nina- Pinta- and Santa Maria.docx
The balance sheet for the partnership of Nina- Pinta- and Santa Maria.docxThe balance sheet for the partnership of Nina- Pinta- and Santa Maria.docx
The balance sheet for the partnership of Nina- Pinta- and Santa Maria.docxlmark1
 
Palindromes A palindrome is a word or phrase that reads the same backw (1).docx
Palindromes A palindrome is a word or phrase that reads the same backw (1).docxPalindromes A palindrome is a word or phrase that reads the same backw (1).docx
Palindromes A palindrome is a word or phrase that reads the same backw (1).docxlmark1
 
Palindromes A palindrome is a word or phrase that reads the same backw (2).docx
Palindromes A palindrome is a word or phrase that reads the same backw (2).docxPalindromes A palindrome is a word or phrase that reads the same backw (2).docx
Palindromes A palindrome is a word or phrase that reads the same backw (2).docxlmark1
 
Palindromes A palindrome is a word or phrase that reads the same backw.docx
Palindromes A palindrome is a word or phrase that reads the same backw.docxPalindromes A palindrome is a word or phrase that reads the same backw.docx
Palindromes A palindrome is a word or phrase that reads the same backw.docxlmark1
 
PAD601 Comment in detail on the events of each date 1880- 1881- 1883-.docx
PAD601 Comment in detail on the events of each date 1880- 1881- 1883-.docxPAD601 Comment in detail on the events of each date 1880- 1881- 1883-.docx
PAD601 Comment in detail on the events of each date 1880- 1881- 1883-.docxlmark1
 
P5- Use the financial information below to calculate and interpret the.docx
P5- Use the financial information below to calculate and interpret the.docxP5- Use the financial information below to calculate and interpret the.docx
P5- Use the financial information below to calculate and interpret the.docxlmark1
 
Pablo own small transportation firm in Latvia- His trucks delivers goo.docx
Pablo own small transportation firm in Latvia- His trucks delivers goo.docxPablo own small transportation firm in Latvia- His trucks delivers goo.docx
Pablo own small transportation firm in Latvia- His trucks delivers goo.docxlmark1
 
Over the past weeks we have been examining the inference process- big.docx
Over the past weeks we have been examining the inference process- big.docxOver the past weeks we have been examining the inference process- big.docx
Over the past weeks we have been examining the inference process- big.docxlmark1
 
Outline the role of the operating system and identify the features of.docx
Outline the role of the operating system and identify the features of.docxOutline the role of the operating system and identify the features of.docx
Outline the role of the operating system and identify the features of.docxlmark1
 
Outline the key issues involved in Open Systems Theory including the f.docx
Outline the key issues involved in Open Systems Theory including the f.docxOutline the key issues involved in Open Systems Theory including the f.docx
Outline the key issues involved in Open Systems Theory including the f.docxlmark1
 
Out of the following- which are non separately stated for Neely Inc--.docx
Out of the following- which are non separately stated for Neely Inc--.docxOut of the following- which are non separately stated for Neely Inc--.docx
Out of the following- which are non separately stated for Neely Inc--.docxlmark1
 
ou shoot a beam of electrons through a double slit to make an interfer.docx
ou shoot a beam of electrons through a double slit to make an interfer.docxou shoot a beam of electrons through a double slit to make an interfer.docx
ou shoot a beam of electrons through a double slit to make an interfer.docxlmark1
 
OS (a) - 5 Points - What is an inode- (b) - 5 Points - How does a soft.docx
OS (a) - 5 Points - What is an inode- (b) - 5 Points - How does a soft.docxOS (a) - 5 Points - What is an inode- (b) - 5 Points - How does a soft.docx
OS (a) - 5 Points - What is an inode- (b) - 5 Points - How does a soft.docxlmark1
 
Organizational Structure Evaluate the decision-making process and its.docx
Organizational Structure Evaluate the decision-making process and its.docxOrganizational Structure Evaluate the decision-making process and its.docx
Organizational Structure Evaluate the decision-making process and its.docxlmark1
 

Plus de lmark1 (20)

The case notes that Nationwide had in mind a simple goal- but faced a.docx
The case notes that Nationwide had in mind a simple goal- but faced a.docxThe case notes that Nationwide had in mind a simple goal- but faced a.docx
The case notes that Nationwide had in mind a simple goal- but faced a.docx
 
The capital budgeting analytical technique that calculates the rate of.docx
The capital budgeting analytical technique that calculates the rate of.docxThe capital budgeting analytical technique that calculates the rate of.docx
The capital budgeting analytical technique that calculates the rate of.docx
 
The balance sheet is the cornerstone of the financial statements- The.docx
The balance sheet is the cornerstone of the financial statements- The.docxThe balance sheet is the cornerstone of the financial statements- The.docx
The balance sheet is the cornerstone of the financial statements- The.docx
 
The capital account balances for Donald & Hanes LLP on January 1- 2011.docx
The capital account balances for Donald & Hanes LLP on January 1- 2011.docxThe capital account balances for Donald & Hanes LLP on January 1- 2011.docx
The capital account balances for Donald & Hanes LLP on January 1- 2011.docx
 
the bookkeeper of vitial inc has asked to assist him with preparation.docx
the bookkeeper of vitial inc has asked to assist him with preparation.docxthe bookkeeper of vitial inc has asked to assist him with preparation.docx
the bookkeeper of vitial inc has asked to assist him with preparation.docx
 
The balanced scorecard integrates financial and nonfinancial measures.docx
The balanced scorecard integrates financial and nonfinancial measures.docxThe balanced scorecard integrates financial and nonfinancial measures.docx
The balanced scorecard integrates financial and nonfinancial measures.docx
 
The balance sheet for the partnership of Nina- Pinta- and Santa Maria.docx
The balance sheet for the partnership of Nina- Pinta- and Santa Maria.docxThe balance sheet for the partnership of Nina- Pinta- and Santa Maria.docx
The balance sheet for the partnership of Nina- Pinta- and Santa Maria.docx
 
Palindromes A palindrome is a word or phrase that reads the same backw (1).docx
Palindromes A palindrome is a word or phrase that reads the same backw (1).docxPalindromes A palindrome is a word or phrase that reads the same backw (1).docx
Palindromes A palindrome is a word or phrase that reads the same backw (1).docx
 
Palindromes A palindrome is a word or phrase that reads the same backw (2).docx
Palindromes A palindrome is a word or phrase that reads the same backw (2).docxPalindromes A palindrome is a word or phrase that reads the same backw (2).docx
Palindromes A palindrome is a word or phrase that reads the same backw (2).docx
 
Palindromes A palindrome is a word or phrase that reads the same backw.docx
Palindromes A palindrome is a word or phrase that reads the same backw.docxPalindromes A palindrome is a word or phrase that reads the same backw.docx
Palindromes A palindrome is a word or phrase that reads the same backw.docx
 
PAD601 Comment in detail on the events of each date 1880- 1881- 1883-.docx
PAD601 Comment in detail on the events of each date 1880- 1881- 1883-.docxPAD601 Comment in detail on the events of each date 1880- 1881- 1883-.docx
PAD601 Comment in detail on the events of each date 1880- 1881- 1883-.docx
 
P5- Use the financial information below to calculate and interpret the.docx
P5- Use the financial information below to calculate and interpret the.docxP5- Use the financial information below to calculate and interpret the.docx
P5- Use the financial information below to calculate and interpret the.docx
 
Pablo own small transportation firm in Latvia- His trucks delivers goo.docx
Pablo own small transportation firm in Latvia- His trucks delivers goo.docxPablo own small transportation firm in Latvia- His trucks delivers goo.docx
Pablo own small transportation firm in Latvia- His trucks delivers goo.docx
 
Over the past weeks we have been examining the inference process- big.docx
Over the past weeks we have been examining the inference process- big.docxOver the past weeks we have been examining the inference process- big.docx
Over the past weeks we have been examining the inference process- big.docx
 
Outline the role of the operating system and identify the features of.docx
Outline the role of the operating system and identify the features of.docxOutline the role of the operating system and identify the features of.docx
Outline the role of the operating system and identify the features of.docx
 
Outline the key issues involved in Open Systems Theory including the f.docx
Outline the key issues involved in Open Systems Theory including the f.docxOutline the key issues involved in Open Systems Theory including the f.docx
Outline the key issues involved in Open Systems Theory including the f.docx
 
Out of the following- which are non separately stated for Neely Inc--.docx
Out of the following- which are non separately stated for Neely Inc--.docxOut of the following- which are non separately stated for Neely Inc--.docx
Out of the following- which are non separately stated for Neely Inc--.docx
 
ou shoot a beam of electrons through a double slit to make an interfer.docx
ou shoot a beam of electrons through a double slit to make an interfer.docxou shoot a beam of electrons through a double slit to make an interfer.docx
ou shoot a beam of electrons through a double slit to make an interfer.docx
 
OS (a) - 5 Points - What is an inode- (b) - 5 Points - How does a soft.docx
OS (a) - 5 Points - What is an inode- (b) - 5 Points - How does a soft.docxOS (a) - 5 Points - What is an inode- (b) - 5 Points - How does a soft.docx
OS (a) - 5 Points - What is an inode- (b) - 5 Points - How does a soft.docx
 
Organizational Structure Evaluate the decision-making process and its.docx
Organizational Structure Evaluate the decision-making process and its.docxOrganizational Structure Evaluate the decision-making process and its.docx
Organizational Structure Evaluate the decision-making process and its.docx
 

Dernier

The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 

Dernier (20)

The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 

Open the provided file ConvertLoop-java Convert the following code so.docx

  • 1. Open the provided file ConvertLoop.java Convert the following code so that it uses nested while statements instead of for statements. Place the new code at the end of the code in ConvertLoop.java . You can reuse the same variables, but be sure to initialize num1 back to 0 and num2 back to 1. int num1 = 0; int num2 = 1; for (int i = 0; i < 5; i++) { num1 = num1 + i; for (int j = i; j > 0; j--) { num2
  • 2. = num2 + (j- 1); } num1 = num1 + num2; System. out .println("T is " + num2); } System. out .println("S is " + num1); Solution I have converted the code in while loop. I hope this would help you. int num1=0; while(num1<5)
  • 3. { num= num1++; int num2=1; while(num2>=num1) { num2 = num2--; } System.out.println(“T is―, +num2); } System.out.println(“S is―, +num1);