I keep getting an error when trying to compile this for Java prog class, below is the instructions for the assignment and my code.
Loop Assignment
Write, compile, and run a Java program that demonstrates the following:
#1. Uses
ach off number down to zero, except the number 3 and 33. Program must use a continue and an if statement.
#2. Uses a while loop to count down from 30 to zero, printing each number, except 27 until the program reaches 5 and then terminates the loop and the program. Program must use a break statement.
#3. Convert #1 to a for loop.
#4. Convert #2 to a do-while loop.
Include each piece of code and screen shot respectively of each program’s output in a Word document.
Access the Loop-Assign document from Week #3. You have already written the code for the four loop problems which you will now combine into one program with four distinct methods. For this assignment 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 with a parameter
one value-returning method without a parameter
one void method with a parameter
one void method without a parameter
Your program must compile and run.
//code below//
public class LOOPmod
{
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.prin tln(counter + " ");}
counter--;
}
}
}
public class LOOP2
{
public static void main(String args[])
{
int counter = 40;
while(counter >= 0)
{
if (counter == 5) //exit
if (counter == 27)break;
counter--;
System.out.prin tln(counter + " ");
counter--;
}
}
}
public class Loop3
{
public static void main(String args[])
{
int counter = 30;
for (counter = 30; counter <= 5; counter++){
System.out.prin tln("*");
{
if (counter % 2 == 1){
if (counter == 33 || counter == 3){
counter--;
continue;}
System.out.prin tln(counter + "*");{
counter--;
}
class LOOP4
{
public static void main(String args[])
{
int counter = 40;
do
{
System.out.prin tln(counter + " ");
counter = counter + 1;
}
while(counter >= 0);
{
if (counter == 5) //exit
counter--;
System.out.prin tln(counter + " ");
counter--;
}
}
}
//below is the error msg that I get everytime//
LOOPmod.java:75 : '}' expected
}
^
1 error
Loop Assignment
Write, compile, and run a Java program that demonstrates the following:
#1. Uses
ach off number down to zero, except the number 3 and 33. Program must use a continue and an if statement.
#2. Uses a while loop to count down from 30 to zero, printing each number, except 27 until the program reaches 5 and then terminates the loop and the program. Program must use a break statement.
#3. Convert #1 to a for loop.
#4. Convert #2 to a do-while loop.
Include each piece of code and screen shot respectively of each program’s output in a Word document.
Access the Loop-Assign document from Week #3. You have already written the code for the four loop problems which you will now combine into one program with four distinct methods. For this assignment 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 with a parameter
one value-returning method without a parameter
one void method with a parameter
one void method without a parameter
Your program must compile and run.
//code below//
public class LOOPmod
{
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.prin tln(counter + " ");}
counter--;
}
}
}
public class LOOP2
{
public static void main(String args[])
{
int counter = 40;
while(counter >= 0)
{
if (counter == 5) //exit
if (counter == 27)break;
counter--;
System.out.prin tln(counter + " ");
counter--;
}
}
}
public class Loop3
{
public static void main(String args[])
{
int counter = 30;
for (counter = 30; counter <= 5; counter++){
System.out.prin tln("*");
{
if (counter % 2 == 1){
if (counter == 33 || counter == 3){
counter--;
continue;}
System.out.prin tln(counter + "*");{
counter--;
}
class LOOP4
{
public static void main(String args[])
{
int counter = 40;
do
{
System.out.prin tln(counter + " ");
counter = counter + 1;
}
while(counter >= 0);
{
if (counter == 5) //exit
counter--;
System.out.prin tln(counter + " ");
counter--;
}
}
}
//below is the error msg that I get everytime//
LOOPmod.java:75 : '}' expected
}
^
1 error
Comment