713 Posted Topics

Member Avatar for Quintia

Gosh this sounds a lot like a homework question. I'm going to assume it is one, and I'm going to be pretty vague. If I fly into San Francisco and I need a vehicle for the week, I go to the car rental stand. I don't ask the person at …

Member Avatar for jon.kiparsky
0
90
Member Avatar for ChieftanBill

[CODE]for(count = 0; count <= values.length; count++)[/CODE] If you use count as an index into values in this loop, it will take you out of bounds, since the last index in values is (values-1). Using (count+1) as the index is just icing on the cake - it puts you out …

Member Avatar for jon.kiparsky
0
246
Member Avatar for zetologos

Can't diagnose it visually - ztini may be right, a problem with your input (is there a leading line without semicolons? That would do it) - but here's two suggestions for diagnosis. 1) you're doing this in a loop - two loops, actually. To pinpoint the error more precisely, put …

Member Avatar for zetologos
0
156
Member Avatar for ComicStix

[CODE] if (sel[i] > max) max = i; [/CODE] This may be your trouble. Is max meant to be a value, or an index?

Member Avatar for ComicStix
0
162
Member Avatar for kvass

James - that's the answer that came to me, but why doesn't it then perform the increment? Clearly the original writer of the code was confused, there's no need to have the assignment there. However, it should work all the same. Suppose it were [CODE]b = a++;[/CODE] You'd expect the …

Member Avatar for JamesCherrill
0
215
Member Avatar for BioJavaPhobic

Scope problem. Declare failurePoint at a higher context: [CODE] boolean FailurePoint = false; for (int i = 1; i < cnodes.size(); i++) { //code ... } [/CODE]

Member Avatar for BioJavaPhobic
0
649
Member Avatar for 24x24

To convert from base N to base ten: start your accumulator variable ("decimal" in your program) at zero start at the least significant (rightmost) digit For each digit, the decimal value is (digit * (N^offset)) where offset is the number of places to the left of the decimal point. (starting …

Member Avatar for 24x24
0
238
Member Avatar for BioJavaPhobic

Looks to me like the problem is the open curly at line 24: [CODE] if (!cnodes.contains(node)) { cnodes.add(node); [/CODE] or rather the lack of a close brace. This means that if the condition is true, you skip all the way down to the end, past your return statements.

Member Avatar for BioJavaPhobic
0
293
Member Avatar for emorjon2
Member Avatar for bullockc83

Or maybe you meant [URL="http://www.libertyorchards.com/category/Aplets_and_Cotlets"]these[/URL]? Tasty!

Member Avatar for javanoob101
-1
126
Member Avatar for r0n

I smell homework here... :) Okay, so start us off. You have a text file. Can you open it and read lines from it, in a loop? Go ahead and do that, just dumping the lines straight to the screen. That'll make a good first step.

Member Avatar for r0n
0
2K
Member Avatar for McCurry0x77

How do you get an indexoutofbounds exception for an index of zero? I suspect that count was inadvertantly initialized to zero, which means there isn't any array there. The main problem visible in the original posting - which jkp corrected, but failed to call attention to, is the for loop …

Member Avatar for jon.kiparsky
0
293
Member Avatar for chiefpf
Member Avatar for plasticfood

Get a piece of paper and walk through it. [ICODE]fun(5): print 5 decrement 5 if 4>0, call fun(4) >fun(4) >print 4 >decrement 4 >if 3>0, call fun(3) >>fun(3) >>... >>>fun(2) >>>>fun(1) >>>>print 1 >>>>decrement 1 >>>>0 is not > 0, so don't fun(0) >>>>then what? >>>then what? >>then what? >then …

Member Avatar for jon.kiparsky
0
156
Member Avatar for livinlife79

And what's the problem you're having? Does the code compile? If the code compiles, what happens when you run it, and how is that different from what you wanted? Please be specific when you ask a question, so you can get the answer you're looking for.

Member Avatar for jon.kiparsky
0
196
Member Avatar for spencer.kindt

You have an algorithm that's pretty clearly stated, all you need to do is code it up. You're right to think that a loop is a good approach: any time you see the same computation repeated n number of times, a loop is likely to come into the picture. Now …

Member Avatar for jon.kiparsky
0
175
Member Avatar for aman rathi

Java is case-sensitive. There's a difference between "string" and String, and between "system" and "System". Capitalize those two words and you should be okay. Java style suggests that class names be in the form MyClassName (first letter of each word in caps) and variable/method names in the form myMethodName (initial …

Member Avatar for aman rathi
0
179
Member Avatar for spencer.kindt

For number 6, that seems like a sound start. For #7, a for loop seems like it'll be useful. For # 8, I'm thinking a while loop. I hope that helps a little. Generally, it's useful to think out a problem like this on paper. Suppose for #7 I give …

Member Avatar for spencer.kindt
0
180
Member Avatar for oliminator123

You've sort of petered out in the middle of a loop. I think you've got the right idea, but you're stuck on the execution. Some tips: -if you have the array declaration in the middle of the loop, it'll overwrite itself each time, and you won't be able to address …

Member Avatar for oliminator123
0
816
Member Avatar for villalandron

You can see from the factorial program that your recursive process works by calling itself on a simpler case, moving towards a trivial base case. For factorial, that base case is: when n = 0, factorial(n) = 1. For any positive integer, you reduce towards that case by decrementing. For …

Member Avatar for jon.kiparsky
0
184
Member Avatar for TheOnlyNemesis

One exit is not something that I would hold up as an ideal - it's one way to get a thing done. The important thing is that a method's logic should be clear, and every path through it should be obvious. Often that means skipping out of the method when …

Member Avatar for jon.kiparsky
0
213
Member Avatar for coco24

Help us out a little. What do you expect to see, and what are you seeing instead? Stating your problem clearly won't just help me and others to solve it, it might actually lead you to a solution.

Member Avatar for anon12
0
82
Member Avatar for infinitus

What this is telling you is that the InputStreamReader does not define an "indexOf" method. This makes sense, since you're talking about a stream, not a persisent entity. It looks like your indexOf is trying to find the position of the input character in the target String - this would …

Member Avatar for harsuraj
0
411
Member Avatar for Newskin01

- StringBuilder is definitely the way to go if you want to assemble a String. Doesn't make a lot of difference in this sort of thing, but you want to get in the habit now, so later on when it matters, you aren't wasting cycles. My rule is, any time …

Member Avatar for jon.kiparsky
0
2K
Member Avatar for Spirit_Guardian

Looks like it's meant to be a constructor, isn't it? Whatever it is, if you take out that line and one of your close curlies, you might have a legal program that does some calculation and then displays a JFrame with nothing in it. At least, the rest of it …

Member Avatar for Spirit_Guardian
0
209
Member Avatar for Oblivious21

You want to put your prompt ("Enter the number of stars in row N") in a for loop, with rows as the upper bound.

Member Avatar for Oblivious21
0
163
Member Avatar for kim.beaul

Oh, dear. No, I'm afraid this is a Java forum. You know, Java, the programming language? The one that isn't HTML, the markup language? Oh, never mind...

Member Avatar for gazzatav
0
169
Member Avatar for 20pav08

Do you mean something like putting a getTextFromTextField1() method in class1, which class2 would call? That's probably what I would do.

Member Avatar for Akill10
0
101
Member Avatar for spencer.kindt

varshakite - Doing the guy's homework for him isn't much of a help. Much better to lead him to the answer, so he has to make the fixes himself. That way he learns something from the exercise, and you improve your skills as a writer in the process - you …

Member Avatar for spencer.kindt
0
283
Member Avatar for banks2140

One piece of confusion that needs to be cleared up here is variable scope. Briefly: Variables exist in the context in which they are declared, and any context contained within that context. Context is defined by curly braces. (more precisely, they exist from the moment they are declared until the …

Member Avatar for jon.kiparsky
0
612
Member Avatar for Katana24

You want to look into OO design a little more. If you're putting these things into an array, there must be a reason they're ending up there - that reason should give you a supertype, an abstract class that you can extend to the classes you need. If you find …

Member Avatar for Katana24
0
199
Member Avatar for avatrin

For your stated purpose, you just need an Ubuntu install disk (or bootable flash drive) and a machine with Windows installed. As for learning to write an OS, I'd say you probably want to start smaller than that. IIRC, Torvalds was trying to write a terminal emulator when he found …

Member Avatar for jon.kiparsky
0
108
Member Avatar for curbster
Member Avatar for kukuruku

You want to sort Strings? Sure, there's library code for that. Strings are Comparable, so if you put them in an array, you can call the sort() method - see the sun reference for [URL="http://download.oracle.com/javase/1.4.2/docs/api/java/util/Arrays.html"]Arrays[/URL].

Member Avatar for btsuper
0
147
Member Avatar for scratchy999

This is in a GUI, I take it? Do you want to validate as they type, or after they trigger a "submit" (via enter key or pushing a button or whatever)? If it's the latter, just get the text as a String, see if it can be parsed as an …

Member Avatar for jon.kiparsky
0
151
Member Avatar for lorettah

I was confused by James' post at first, and then I realized that what he calls "brackets" are what I call "parentheses". Brackets, to me, are [] and {}. The trouble here is with (). [QUOTE]Next time post your code in code tags and post the complete compiler error message …

Member Avatar for jon.kiparsky
0
122
Member Avatar for Amoryethel

- I agree that Bird is a class, not an interface. For the most part, interfaces define capabilities, classes define things and types of things. "Aviator" might be an interface, it would tell you that implementing classes have a method "fly()". -Since you don't want to have a generic Bird …

Member Avatar for Amoryethel
0
145
Member Avatar for eikal

[QUOTE]im thinking i didnt do the "cases" right [/QUOTE] You're right - pcpick is not initialized in all of the possible branches of your switch statement - if you get something other than 1, 2, or 3, it's never given a value, and that's not allowed. Easiest solution is to …

Member Avatar for eikal
0
184
Member Avatar for Sonny101

... in the setValue(String) method, that is. [CODE] public void setValue(String value){ double s = Double.parseDouble(value); }[/CODE] This sets a local variable, which is then lost when the method ends. Add Sanjay's line (above) and you're set.

Member Avatar for jon.kiparsky
0
146
Member Avatar for Lourdupinto
Member Avatar for triceratops

You'll need at least one class if you're going to make this in java, but we'll let that be. You're going to have to figure out what the flow of this program will be, and write methods to do the work that you need done. Take a sheet of paper …

Member Avatar for jon.kiparsky
0
113
Member Avatar for Nathan Campos

I'm still not seeing a "getString()" method for TextField, or setString(), either. getText() and setText(), yes, but not getString or setString. This shouldn't be your problem - calling non-existent methods doesn't throw an NPE. To get this exception, your textBox3 must be null. Put in this line before the call …

Member Avatar for jon.kiparsky
0
201
Member Avatar for Beschatten

As a matter of coding style, you might start by making your boundaries into constants. In this simple little example, it doesn't look like it saves you anything, but suppose you were writing something where these values were used across multiple class files. You don't want to change three class …

Member Avatar for jon.kiparsky
0
123
Member Avatar for Abdel_eid

Entering in a JTextField? I'd probably try addint a KeyListener. When it fires a keyTyped KeyEvent, get the current text and off you go.

Member Avatar for Abdel_eid
0
97
Member Avatar for Neversleepin

So you're using this pattern to split on - doesn't that eliminate anything that matches the pattern? If I split "a+b+c" on "+", I get ["a", "b", "c"] - what happens when you run this on Anyone Someone Something Somebody Science Some other word I would expect ["Anyone","Something","Somebody","Some other word"] …

Member Avatar for Neversleepin
0
139
Member Avatar for jemz

max is a shorthand for "a function returning the maximum of two numbers". You'll find an implementation of such a function in java.Math.

Member Avatar for jemz
0
190
Member Avatar for Magekiller

[CODE]for (int i = 1; i <= (11 - 2 * line); i++) { System.out.print("*"); [/CODE] This will print "*", ( 11- (2*line) ) times. So if [ICODE]line == 5[/ICODE], it'll print "*", if [ICODE]line == 1[/ICODE] it'll print "*********" So given that your outside loop descends from 5 to …

Member Avatar for jon.kiparsky
0
92
Member Avatar for Neversleepin

Try this as your regex: "^[S2]" "^" is the start-of-line anchor, and [S2] matches either of those characters, so this should match what you're looking for. (But I could be wrong, regex isn't really my forte)

Member Avatar for Neversleepin
0
2K
Member Avatar for CHOCHOCHO
Member Avatar for stroper

Forget about the timer for the moment. What does the guess() method look like? That'll depend on whether this is running in a command-line or a GUI situation, but they're pretty much the same at bottom: you want to enter a state in which the user enters words and they …

Member Avatar for mangopearapples
0
1K

The End.