713 Posted Topics
Re: [QUOTE=cscgal;1314743]Do you read the DaniWeb news stories? If not ... what about them doesn't interest you?[/QUOTE] I read a few pieces. I hate to be the one to have to say it, but this is not a news-gathering organization and it's not going to be one. The "articles" are sort … | |
Re: Pardon me, I don't know that I understood the question properly. Are you asking what an abstract class is used for in Java? | |
Re: How is this different from what Tong posted? | |
Re: [CODE]for(int i=rowStart;i>rowEnd;i--){ // it should reduce 8 to 7. for(int j=columnStart;j>columnEnd;j--){// it should reduce 3 to 2 while(pieces[i][j]==null){ a++;// here it should count, the number of times a square is equal to null. } [/CODE] If it starts, this while loop will run forever: you do not update the test … | |
Re: [QUOTE]Or simply put the header as: import java.util.*;[/QUOTE] importing java.util.* is seen as bad form in some circles. Generally it's good to make your imports explicit so it's obvious what you're using; this way the import statements are informative to the coder who comes after you. ("I can see you … | |
Re: To insert a % in a printf, you use another % to indicate it's a literal % character: %% So your expression would look like " %%%.3f", aIR); As for the print statement, if you put an [CODE]if (value is out of range) print (error message);[/CODE] at the top of … | |
Re: As always, the first step is to break it down into pieces that you can deal with. Break it into logical steps, save the coding for later. Assume that you're a computer, and have only simple arithmetical steps at hand. How would you go about calculating the correct output? (hint: … | |
Re: [QUOTE=NewOrder;1329878]is this a syntax mistake? No, the syntax is fine. The logic is possibly flawed, though. [CODE] if(pieces [a][b]!=null){ array[a][b]=pieces [9-a][b].print(); } [/CODE] wont if filter the nulls out. and leave me with the objects which i will be able to apply my method to? [/QUOTE] No, it won't do … | |
Re: [QUOTE] I hate it when people correct me on a stupid mistake that I should've seen myself, so I guess I'm also playing The Game :)[/QUOTE] Paraphrasing Jonathan Swift, I think: "One should never be ashamed to be found in an error, for that only means that you know more … | |
Re: There are a couple of things you could mean here. If you want, you could call this method from Map, and assign the return value to some locally available String. [CODE] someString = RoomType.n(someStringArray);[/CODE] On the other hand, you might mean that you want to run this once and refer … ![]() | |
Re: [QUOTE=ezkonekgal;1329488]thanks for the link. its helpful. Maybe we'll just limit the operators that the were gonna include to count. am really confused as to how to count dem. i'm thinking of comparing. Like wen the code reads the file, if it encounters like for example +=, it checks if it, … | |
Re: Autocomplete is one of the worst features anyone has come up with - I can't bear machines that try to do my thinking for me. People finishing your sentences, that's bad enough, I won't put up with it from a machine. But I betcha the marching morons will love it … | |
Re: So you've got Eclipse running, but you can't find a "web application" button? Is that the problem? | |
Re: [QUOTE=extemer;1328547] [CODE]class printing{ public static void main(String[] args){ for(int i=1; i<=10; i++) { for(int j=1;j<=5;j++) System.out.print("@"); System.out.print(""); }}[/CODE] [/QUOTE] Is this exactly the code you're running? Did you copy and paste this, or did you re-type it. The easiest way to get this into an infinite loop would be to … | |
Re: This has got to be a windup. Please tell me there's some surrealist humor that I'm not getting here. | |
Re: Of course, you don't know where the tag starts or how long the text is, so [CODE]subString(s.indexOf("<text>")+"<text>".length(), s.indexOf("</text">));[/CODE] would be closer to it. If that's difficult to read, take it apart piece by piece: "<text>" is a string, so it has the String methods, so "<text>".length() returns 6 - why … | |
Re: There are other ways of doing it. Since I'm not sure exactly what you're doing, I'm not sure if they're more efficient, but there are always other ways to do anything. If you want it to be locked in to just printing that one string, that one way, probably it's … | |
Re: A good example of the difference between calling a function and reading a variable. | |
Re: I'm pretty new here, but in the last week I've seen far too much of all of the above. The thing that gets me is the "Here, I've written your code for you" posts - completely uncommented, without a hint of an attemt to explain what it is about this … | |
Re: Integer division discards remainders and returns the integer result, so for example 5/2 evaluates to 2 - there are two twos in five. Under integer division, x/y means "how many times can I subtract y from x and still get a positive result?" So in your calculation, 10/100 comes out … | |
Re: There isn't a distinct format specifier for doubles as opposed to floats. The %f is used because C programmers are used to it. Really, it's the right thing: it means "floating-point number goes here", and a double is just a sort of floating-point number - one which uses twice as … | |
Re: Yes, please do ask him about this, and let us know what he says. I don't think it's likely that you can annoy a teacher by showing an interest and trying to learn more. It might be best to pursue it during office hours or after class, because he's probably … | |
Re: It looks like you're entering a non-integer value when you run the program. Does it do this when you enter a 1? | |
Re: [QUOTE=NormR1;1324790]Many people use an IDE when they make a program, however you can use any text editor to do it.[/QUOTE] Ooh, ooh, can we have the IDE versus editor war? I dibs vi! :) | |
Re: When you do this sort of println debugging, you should be testing a hypothesis. Go through the code and try to figure out what each value [B]should be[/B], in your understanding of the code. Start with your line [CODE] number1 = input.nextInt();[/CODE] (ahem, code tags next time, so I have … | |
Re: Why do you want to get at the other class's data? Better to let that class tend to its own knitting. The less data you share, the easier your code is to manage. Why is that? Well, if you have a class that depends on data from another class, sooner … | |
Re: [QUOTE]I am using recursion inside a loop. I want to stop the loop as soon as the method is called recursively and resume it again when the call returns[/QUOTE] At first blush, this sounds like a strange thing to want. I'm not sure I really understand what you mean. Do … | |
Re: Criticizing amateur poetry is too much like shooting ducks in a barrel. Anything I could say about this particular poem would tend to discourage you from writing more, which I don't want to do. So instead, some advice from a non-poet: Thank you for working metrically - non-metrical poetry is … ![]() | |
Re: Be careful with your class names and object names. You have MyInteger (a class) and myInt (an occasional object, a formal parameter of certain methods) and sometimes you try to call MyInt.someMethod(), but MyInt doesn't seem to exist. If you're calling a static method, you use the class name, if … | |
Re: i is out of scope when you get to the return (line six of your last post) In any case, it would be an int, while getRoom should return a Room (as you correctly specify in the method declaration) I can't tell what sort of thing a RoomReference is, but … | |
Re: So the problem is not with your code, but that you can't get a screen shot in Vista? Sorry, can't help you there. Have you tried a Windows forum? | |
Re: Here are some observations to begin with: - You do know, don't you, that there is an ArrayList class available to you already? It's a pretty handy class, you should look it up. (pick your favorite search engine and look for "java arraylist" and the complete description from Sun will … | |
Re: How large an array will you need to deal with? If it's a small enough array, you could probably do something simpleminded like go through the original, grab the minimal element, and add it to the new array (easier with ArrayLists, but doable with ordinary arrays). Lather, rinse, repeat. This … | |
Re: What happens when you go to run it? Is it a logic error (you get a result, but it's not the one you think it should be) or is it a failure to compile (what does the gobbeldygook from the compiler look like?) or a run-time failure (throws an exception … | |
Re: Rule of thumb: if masijade says it, it probably works. I'm just sayin', the guy knows his stuff. Second rule of thumb: "it doesn't work" is not a useful error report, and will probably get you nothing useful back. Next time, say what you tried, what you expected to happen, … | |
Re: Two points, while I find my way to your actual problem - when you're marching up the line of numbers in your isPrime(), you can actually stop when you get to the halfway point, since you know that there is no integer factor of n greater than n/2. - Could … | |
Re: "can't support bigger size" - you mean, the array doesn't resize dynamically? The arraylist is one good solution, but you can make a method to increase your array size when it gets too big. That's a pretty simple thing to do. Your method would simply declare a new array of … | |
Re: First thing, try parsing the input (ipt) as an int. Much friendlier. If I can understand what you want to do, you want to make methods for finding the area of your various shapes and call them in your case statement? Not difficult. Where are you starting from? Do you … | |
Re: Interesting problem. So you've got the first part right - getting the size of the array. Since it's promised to be a square matric, you can accept one parameter as input, that being the length of one side. (4, in this case). So you could generalize this by getting a … | |
Re: There are three things that could be null in that line that I can see. Those are model, ref1, and the return from getRoom(ref1). Try preceding the line with some test code. Something like [CODE]System.out.println( (model==null)? "Model is null" : model.toString());[/CODE] is a good frame. Put this before the line … | |
Re: You can only return one item from a method - period. However, that item can be a complex object. For example, if you made a method which calculated a location on a graph, you could not return two ints (x,y) but you could (and would) return a Point object, from … | |
Re: Try the "file" command. It'll look up the magic number and try to tell you what program created the file. | |
Re: I agree. You don't even need to make a separate program. You can make a method in your current program that opens a file and returns an array. Make a little driver program whose only purpose is to call that method and print out the array. When it looks like … | |
Re: My advice is to optimize for programmer time, not for run time. A simple change to the program might take you fifteen minutes to an hour. A major change to a serious program might take days or weeks. The time-to-kill of a typical bug depends mostly on how well the … | |
Re: So you want to validate the input, and you have a list of conditions that you're supposed to verify? Easy enough. Why don't you take them one at a time, and make a method to verify each? For example, for your first one, you'd want [CODE]public void everySquareIsFilledIn() { // … | |
Re: Has anyone ever managed to figure out why it is that people feel the need to post solutions to homework problems? It seems quite pointless, especially when it's in a thread that's two years dead.... | |
Re: Well, it's not such a weird problem. K&R spend most of their time showing ways to rewrite library code, this is a good exercise. We could assume that the input is a String, but then we have to assume some String methods, and then it's just too easy. So let's … | |
Re: I'd second Norm's advice. Start simple, build up. In the mean time, what was the trouble you were having with rounding? I didn't see it in your code, and searching didn't turn up an instance of "round". Math has a lot of ways to turn floating-point numbers into integers, all … |
The End.