473,654 Members | 2,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Anyone!!!! Asap Please

7 New Member
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 1369
sicarie
4,677 Recognized Expert Moderator Specialist
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
ToAsTeEJaVa
7 New Member
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 InputStreamRead er(System.in));

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

System.out.prin tln("Tik Hoeveelheid Extras in: 1 - 5");
String sExtra = in.readLine();
int iExtra = Integer.parseIn t(sExtra);


NOV05V3 nov = new NOV05V3(iGroot, iExtra);

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

}
}
Nov 8 '06 #3
sicarie
4,677 Recognized Expert Moderator Specialist
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
ToAsTeEJaVa
7 New Member
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 Recognized Expert Moderator Specialist
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
1141
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 help. Please if anyone can gide me through i will be so grateful!! I have pasted my code below
7
3594
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> </head> <style type="text/css">
4
1518
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 " and put it in var "link" And extract "some text" and put it var "text",. So basically extract all between <a href=" and " >
4
1522
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 procedure. If there are no records returned then this would give me an indicator and I can re-direct the page somewhere more appropriate. Well this is the theory. I have never used datatables before and am not sure how to implemenet what I want so I was...
8
1652
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 DataGrid1 when the DropDownList1 (which consists of Topic) is clicked. I have the following code: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then
1
2049
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: SortedList(); SortedList(const SortedList& aSortedList); ~SortedList();
2
3239
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: error: cannot convert `char (*)' to `int*' for argument `1' to `void showArray(int*, int)' 33: error: expected unqualified-id before "for" 33: error: expected constructor, destructor, or type conversion before '<' token 33: error: expected...
13
1810
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 backgound image which will have variable text written in front of it. I am having trouble geting labels and text boxes to print, along with the inlarged image that is printing. The labels and text boxes need to appear infront of the image. And where do I...
2
1448
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. MCA
0
8708
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.