Answer to Question #174216 in Java | JSP | JSF for Jean Claude

Question #174216

(i) Identify and correct the errors in each of the following sets of code: [6 marks] i. while ( c <= 5 ) { product *= c; ++c; ii. if ( gender == 1 ) System.out.println( "Woman" ); else; System.out.println( "Man" ); iii. What is wrong with the following while statement? while ( z >= 0 ) sum += z;


(ii)Explain two (2) programming situations that will require the use of overloaded methods [5 marks]


1
Expert's answer
2021-03-22T12:43:58-0400
public class Main
{
	public static void main(String[] args) {
	//initialize variables
		int product = 5;
		int c = 4;
		while (c <= 5) {
			product *= c;
			++c;


		}
		System.out.println(product);
		//first initialize variables before him using
		int gender = 0;
		if (gender == 1) {
			System.out.println("Woman");
		} else {


			System.out.println("Man");
		}
		//initialize variables z and sum
		int z = 0;
		int sum = 1;
		while (z <= 0) {
			sum += z;
			//Should be a break condition for stopping  while loop othervice it will infinite.Other solution change the condition:: inside the while loop.
		}
	}
}
//(ii)Overloading in Java is the ability tocreate multiple methods of the same name, but with different parameters.
//The main advantage of this is cleanlinessof code.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog