Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hrllo This Question is related to JAVA Please don\'t use your handwrting thank y

ID: 3710577 • Letter: H

Question

Hrllo

This Question is related to JAVA

Please don't use your handwrting

thank you

Purpose

Strengthening your understanding of the while and for loops.

Brief Introduction

Think of a simple programming problem that can be solved by using a loop, and briefly describe this problem (it should not be one of the examples discussed in the slides). Then, solve it by using either the while loop or the for loop, and explain your solution to your classmates.

Your explanation should answer at least one of the following questions:

Why did you choose to solve it by using the while [or for] loop?
How does your code work?
Hand-trace* your code to show how the values of the variables change during the execution of your loop.
You may also want to show that your loop will always terminate.
You must also post a response to at least one of your classmates. In your response, you may:

Disagree with using while [or for] loop for the problem described.
You may also identify a mistake in your classmate’s code or hand-tracing.
For example, their code may suffer from an “off-by-one” error.
* "When you hand-trace code, you write the names of the variables on a sheet of paper, mentally execute each step of the code, and update the variables".

Action Items

Find a simple problem, solve it using a loop, and explain your solution.
Respond to at least one other post.

Purpose

Strengthening your understanding of the while and for loops.

Brief Introduction

Think of a simple programming problem that can be solved by using a loop, and briefly describe this problem (it should not be one of the examples discussed in the slides). Then, solve it by using either the while loop or the for loop, and explain your solution to your classmates.

Your explanation should answer at least one of the following questions:

Why did you choose to solve it by using the while [or for] loop?
How does your code work?
Hand-trace* your code to show how the values of the variables change during the execution of your loop.
You may also want to show that your loop will always terminate.
You must also post a response to at least one of your classmates. In your response, you may:

Disagree with using while [or for] loop for the problem described.
You may also identify a mistake in your classmate’s code or hand-tracing.
For example, their code may suffer from an “off-by-one” error.
* "When you hand-trace code, you write the names of the variables on a sheet of paper, mentally execute each step of the code, and update the variables".

Action Items

Find a simple problem, solve it using a loop, and explain your solution.
Respond to at least one other post.

Explanation / Answer

solution:

i want to print 1 to 10 numbers in my console output.then we need to write 10 output statements in the program.

i want to print elements in the array for printing we need to iterate the array. if 100 elements in array we need to write 100 times system.out.println in our program.in this case for loops are so useful

for(int i=0;i<10;i++)//for (initialize the condition:termination;increment)

{

system.out.prinntln(i) //printing

}

//for loop syntax

for(initialization condition;termination condition;increment/decrement)

{

//printing statement or business logic

}

//first control comes to initialization condition then it comes to inside of the forloop it executes.

//then it goes to increment or decrement in the above for loop i value will be incremented by 1

//finally it goes to termination checks whether i value less than 10 or not it is true then it goes to inside and prints it

//again after printing it goes to increment after that checks the termination below 10 or not if it is true come to the inside of the loop and executes it .

//this process will done until the i value lessthan 10 once termination condition fails it will terminate.the for loop will be closed.

While

while(boolean condition)

{

print x;

}

while loop is also same as for loop.but a small difference is there.

in the for loop we know the termination condition i<10;

but here in some cases we dont know the termination condition then we go for while loop.

example for same

int i=0;

while(i<10)

{

system.out.println(i);

i++

}

//here we need to increment the i value manually.

//for loop basically i want to print array or elements but i dont know how many elements in the array .in this situation we go for while loop.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote