473,395 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Java Looping problem

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.println(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.println(counter + " ");
counter--;
}
}
}
public class Loop3
{

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

for (counter = 30; counter <= 5; counter++){
System.out.println("*");
{
if (counter % 2 == 1){
if (counter == 33 || counter == 3){
counter--;
continue;}
System.out.println(counter + "*");{
counter--;
}

class LOOP4
{

public static void main(String args[])
{
int counter = 40;
do
{
System.out.println(counter + " ");
counter = counter + 1;
}

while(counter >= 0);
{
if (counter == 5) //exit
counter--;
System.out.println(counter + " ");
counter--;
}
}
}

//below is the error msg that I get everytime//

LOOPmod.java:75: '}' expected
}
^
1 error
Feb 1 '07 #1
4 2480
r035198x
13,262 8TB
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.println(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.println(counter + " ");
counter--;
}
}
}
public class Loop3
{

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

for (counter = 30; counter <= 5; counter++){
System.out.println("*");
{
if (counter % 2 == 1){
if (counter == 33 || counter == 3){
counter--;
continue;}
System.out.println(counter + "*");{
counter--;
}

class LOOP4
{

public static void main(String args[])
{
int counter = 40;
do
{
System.out.println(counter + " ");
counter = counter + 1;
}

while(counter >= 0);
{
if (counter == 5) //exit
counter--;
System.out.println(counter + " ");
counter--;
}
}
}

//below is the error msg that I get everytime//

LOOPmod.java:75: '}' expected
}
^
1 error
Indent your code and post it using code tags.
Feb 1 '07 #2
< incorrrect spoonfeeding code removed (JosAH) >
Nov 5 '08 #3
karthickkuchanur
156 100+
check the Paranthesis which block are open and closed correctly
Nov 6 '08 #4
itsraghz
127 100+
//below is the error msg that I get everytime//

LOOPmod.java:75: '}' expected
}
^
1 error
The answer is in the line number itself. It says that one of the matching brackets are missing in the program. Just check for the total number of starting and ending braces/brackets.
Nov 6 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

54
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I...
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
4
by: Skeleton Man | last post by:
Hi, Upon installing Oracle 9i (9.2.0.1.0) on a Debian box, the whole install process completes, but when I get to the very end and it trys to setup configuration assistants, all three fail with...
3
by: Markus Dehmann | last post by:
I have a two different value types with which I want to do similar things: store them in the same vector, stack, etc. Also, I want an << operator for each of them. class Value{}; // this would...
4
by: google | last post by:
Dear newsgroup, I give up, I must be overseeing something terribly trivial, but I can't get a simple (Java) applet to react to incoming (python) SocketServer messages. Without boring you with...
3
by: Dave128 | last post by:
Let me first start off by saying I am a beginner at Java. I need help on an assignment to produce a loop which I believe for this particular assignment would be the for loop. The output needs to look...
12
by: steven acer | last post by:
hello, i have a java app that constructs an xml from a specific file format and vice versa. i've been asked to convert it to c++, but im not an expert in c++, actually im mere beginner you can...
3
by: Vic Spainhower | last post by:
Hello, I have an HTML table that is being constructed from a MySQL table and displays a form that includes a check box on 1 of the fields on the form for each record. I have included in this PHP...
1
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.