How to combine more programs into single program


Discuss the below:

Task:

You have already written the code for the four loop problems which you will now combine into one program with four distinct methods. You will write methods, two value returning methods and two void methods. You may choose which of the four problems are coded into which method. Each method must represent one of the 4 distinct loop problems. The methods must include: one value-returning method and one void method which will receive a formal parameter and one (each) that will not. Your program must compile and run.

public class LOOP
{

public static void main(String args[])
{
int counter = 40;

while(counter >= 0)
{
if (counter % 2 == 1){
if (counter == 33 || counter == 3){
counter--;
continue;}
System.out.println(counter + " ");}
counter--;
}
}
}

public class LOOP2
{
public static void main(String args[])
{
int counter = 30;

while (counter >= 0)
{
if (counter == 27){
counter--;
continue;}
if (counter <= 4){
break;}
System.out.println(counter + " ");
counter--;
}
}
}

public class LOOP3
{
public static void main(String args[])
{
int counter;

for (counter = 40; counter >= 0; counter--)
if (counter % 2 == 1){
if (counter == 33 || counter == 3){
continue;}
System.out.print(counter + " \n");}
}
}

public class LOOP4
{
public static void main(String args[])
{
int counter = 30;

do
{
if (counter == 27){
counter--;
continue;}
if (counter <= 4){
break;}
System.out.println(counter + " ");
counter--;
}
while (counter >=0);
}
}

Solution Preview :

Prepared by a verified Expert
JAVA Programming: How to combine more programs into single program
Reference No:- TGS01935719

Now Priced at $25 (50% Discount)

Recommended (97%)

Rated (4.9/5)