473,385 Members | 1,531 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,385 software developers and data experts.

Help Anyone!!!! Asap Please

I need to repeat a set of instructions but if the user enters a certain character or number e.g. 0; the program should stop...
what methods can I use for this?

I have tried to use a "for" method but there is no way to break the cycle!
and so I have tried a "while" method too but our handbook fails to specify how to stop a program.

please help me asap!
Nov 8 '06 #1
5 1356
sicarie
4,677 Expert Mod 4TB
I need to repeat a set of instructions but if the user enters a certain character or number e.g. 0; the program should stop...
what methods can I use for this?

I have tried to use a "for" method but there is no way to break the cycle!
and so I have tried a "while" method too but our handbook fails to specify how to stop a program.

please help me asap!
I would use a 'while' loop.

http://java.sun.com/docs/books/tutor...lts/while.html

Check this out, and feel free to ask questions on anything you don't understand.
Nov 8 '06 #2
I Hope you guys understand afrikaans 'cause Here is my code:
---------------------------------------------------------------------------------------------------------------------
import java.io.*;

public class TNOV05V3
{
public static void main(String[]args) throws IOException
{
BufferedReader in = new BufferedReader
(new InputStreamReader(System.in));

for(int k =0;k<=5;k++) //using a for code
{
System.out.println("Tik Groote in asb. 1 - 3: ");
String sGroot = in.readLine();
int iGroot = Integer.parseInt(sGroot); //want program to end here if 0 is typed

System.out.println("Tik Hoeveelheid Extras in: 1 - 5");
String sExtra = in.readLine();
int iExtra = Integer.parseInt(sExtra);


NOV05V3 nov = new NOV05V3(iGroot, iExtra);

System.out.println("Groote : " + iGroot + " is: " + nov.geeGroote());
System.out.println("Extras : " + iExtra + " is: " + nov.geeExtras());
System.out.println("Koste is: " + nov.geeKoste());
}
System.exit(0);

}
}
Nov 8 '06 #3
sicarie
4,677 Expert Mod 4TB
Yeah, just change the for loop to a while loop, and for the expression, you just check it against iExtra. (That's what i would do, anyway)
Nov 8 '06 #4
if I put the while in the "for" place it is out of scope range and thus does not find the symbol variable iExtra.

any ideas?
Nov 8 '06 #5
sicarie
4,677 Expert Mod 4TB
Right, it did - the variables iGroot and iExtra only exist inside that loop, and are undeclared at the initialization of the while loop. You need to declare them outside of the while loop.

Also, I just read the comment that said //end here if iGroot is 0, so you can change the while conditional to compare to iGroot.

From there it works, I got it to build successfully with those modifications.
Nov 8 '06 #6

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

Similar topics

1
by: the_proud_family | last post by:
HELP ME PLEASE!! I can't get the ball to go up right side and then I need it to turn around and keep turning until velocity=0 I have been at it for the past 2 weeks now i give up and call for...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: kirill_uk | last post by:
Help with extracting please folks.! Hi. I have this: a variable like: <a href="http://www.some_html.com/text.html" >some text</a><br> I heed to extract the "http://www.some_html.com/text.html "...
4
by: Stephen | last post by:
I am trying to add some code to below to include a datatable and fill the datatable. The reason for doing this is so as I can check to see whether there are any rows returned by the stored...
8
by: Sandy | last post by:
I have two tables, tblPost - (Cols PostID, TopicID, UserID, Question, PostMsg and PostDT) and tblTopic - (Cols TopicID, Topic). I am trying to get tblPost.Question and tblPost.PostDT into...
1
by: dtefran3 | last post by:
The problem Implement a SortedList class which stores a list of int data in ascending order. Program requirements The public interface of your class is as follows: class SortedList{ public:...
2
by: k1ckthem1dget | last post by:
I need to display the unsorted list of names and display the sorted list of names. My program is getting a bunch of errors though, and i dont know why. I am getting the following errors. 28:...
13
by: robert10 | last post by:
Hi, I have recently added some code to my form in regards to resizing an image on Print. I have an image that does print correctly after its been resized, howver i'm needing to use it as a...
2
by: jafarsibtain | last post by:
hi.. I am creating a form where there are two combo Boxes (drop Down) > Program_Combo_box > Course_Code_Combo in the Program Combo Box there are five items in the list > 1. BIT 2.BCA 3....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.