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

Can someone help point me in the write direction on how to write this short pape

ID: 3539642 • Letter: C

Question

Can someone help point me in the write direction on how to write this short paper?;


Think about a program you use that needs a while loop statement.
Using your example, write a short paper on what your program does. Include the logical expression and what type of while loop (EOF, sentinel-controlled, counter-controlled, flag-controlled) you need. Using the same logical expression as above, use a different while loop to evaluate the expression. Explain what while loop you used and how it changes your program.
You can refer to the Java Programming Tutorial on while loops for assistance.


Not sure where to start or how to go.

Explanation / Answer

/*an application that reads a nonnegative integer from an input dialog and computesand prints its factorial.*/


import java.util.Scanner;
public class Factorial {

public static void main( String args[] )
{
//String input;
int //number = 0,
input, // user input
factorial; // factorial of input value

factorial = 1;

Scanner kbinput = new Scanner( System.in );

System.out.print( %u201CEnter a positive Integer: %u201D );
input = kbinput.nextInt();
System.out.print( %u201D You entered: %u201D +input+%u201D.%u201D);
//number = Integer.parseInt( input );

// calculate factorial
while ( input > 0 ) {
factorial *= input;
input%u2013;
}

System.out.print( %u201C 5! is %u201D + factorial+%u201D.%u201D );
} // end method main

}



This program calculates factorial(n), where n = integer. factorial(n) = n x (n-1) x (n-2) x ... x 1

i.e. factorial(3) = 3 x 2 x 1 = 6


It is a counter controlled while loop. when the counter (in this case variable input) becomes zero, the loop terminates.