masijade 1,351 Industrious Poster Team Colleague Featured Poster

Edit: Nevermind.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Point taken, especially that no effort by Sunshineserene in at least delivering a sample code. ...That is the point...we should point that out to him, but do not be obsessed by the fact that you are doing homework for people, that you are helping people and that kind of stuff!!!! If these guys want their homework done, there are many avenues of doing such including paying to get perfect code.

No. The point is that he should write the code and others here should help him crrect it. The code should come from him and not you. Give a few hints at to what is to be done and let him do it. If it doesn't work he should post that code and ask for further help/clarification. Then you give him the next clue(s) as to what he has done wrong and let him try again. You still do not post a complete code. Repeat the process until the problem is solved. Guaranteed something will have been learned in that process in a manner that will stick. Normally, when provided with code, even if they do look at it and say "Oh, okay, now I understand", it is still something that is, normally, quickly forgotten, and so, useless.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

A hash with the values as keys and a one up number as the values.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

End of string.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Masijade indeed if this is his homework, Sunshineserene should be advised to avoid copying it because I must have been out of my mind to post the code:

Sunshineserene I understand your concern just study the charAt() method.

Oh C'mon how can you think it is not homework? What real-world application would ever need what is descibed there? And, knowing that, how do you think that doing it for him teaches him anything? He'll take it and hand it in and that's that, and tommorrow he will be even more lost than he was today.

However, if you insist on continuing to do homework for people, hopefully they come to work at the same company you work for (if you even do, yet, or ever) so that you can continue doing their work for them and let them get paid for it and you eventually get fired since your own work is not getting done.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

mbugua, do you consider the OP too stupid to understand the first reply so that you found it necessary to do his homework for him?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No, use the newLine method of the filewriter as already stated. Different systems use different line endings and you should be using the line ending for the system you're running on (and the newLine method guarantees this) unless you have a specific reason for doing otherwise.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What do you think the "toCharArray" method of String is for?

See the API docs for String.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, the console is probably using a courier font, and the "file editor", whichever it is, is probably using another font.

Or, if you mean because there are no "newlines" in the file, then add a call to fileWriterVar.newLine() after the fileWriterVar.write(...) call.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Is there whitespace at the end of the string?

Try with str.trim().starts... and str.trim().ends...

Or do str = str.trim()

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Anymore?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That "code" doesn't even fit that "explanation".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I don't need to as I know it doesn't help. First, the OP is already past the part of reading the file and secondly (among others) using == true and == false is just plain braindead coding.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Hi,

I wrote for you an entire function see below

public void extract(String str1)
{
String str2 = null;
File file1 = new File(str1);
FileReader fr = new FileReader(file1);  
BufferedReader br = new BufferedReader(fr); 

while(br.readLine() != null)
{

str2 = br.readLine();

if(((str2.startsWith("ATOM") == true)) && (str2.endsWith("H") == false))
{
System.out.println(str2);
}

else
{
//do something if you want
}

}

}

The argument is the file location as a string

Richard

And how does this help?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

When you create a FileWriter you are creating a new file or overwriting an existing file (unless you use another constructor, but we are not going to get into that as it is not applicable here), as a look at the API docs would have clearly spelled out. So, create and close the FileWriter in the same places as the FileReader and simly write to it in the loop.

You really need to learn how to read the documentation, and then actually do that. You also really need to learn some investigation skills rather than hoping someone else will solve your problems for you. All of this has been fairly (when not really) simple problems with a little thought and investigation and all these threads of yours have taken days (actually weeks).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Look at the API for Color. What are those int values in that statement?

Now, what do you think you might try if you want Green?

In any case, see the Class JColorChooser, and then Google for the JColorChooser demo and run it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Simply show the lines that match. If you need to write them to a new file, then you also, of course, need a FileWriter.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What do you want to do? Do you simply want to display them, or do you wish to process the data in some way?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

$ matches end of String so how can you have the H after the end of String. And, of course, you want to match to the read String ("str") not to some bogus string "filename". What was that suppossed to achieve?

Also, why not startsWith and endsWith as already suggested (in a few of your other threads on this)?

if (str.startsWith("ATOM") && !str.endsWith("H")) {

will give all lines that start with ATOM and do not end with H. Is that not what you wanted?

P.S. Actually posting the code you try (as you finally did) rather than simply whining that it doesn't work, or doggedly pursuing your original path (which you'd already been told won't work), allows us to finally help you fix, and allows you to finally advance.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yes, and No. A implements, and so, by default, those methods are "available" through the B Class, since B is an A, but B, it self, does not, technically, implement the other interface.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

As also said here. And, there was an old thread in which I had already said this, too. Stop starting new threads simply because you don't like that people are not telling you "yeah you're doing everything right, Java is just corked and so it's not working".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And again, here.
Closing both this thread and the referenced (in this post) thread.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

As I have told someone else (you I believe) use a BufferedReader, while, reader.readLine, string.startsWith, and string.endWith.

Give that a try and post the code, if it "doesn't work", with a complete description of the difference between expected and actual results, along with any and all compiler/error messages.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I'm sorry, but Google's first hit looks promising, doesn't it?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

:sigh:

Closing Thread.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

start a new thread to ask a question and then post your code and any (and all) error/compiler messages along with a complete and concise description of expected behaviour versus actual behaviour.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay.
public static what String()
or
public static String what()

Which is it?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Maybe we could if you described the problem, but don't expect any cut-n-paste code answers, of course.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, seeing as how you haven't asked anything I don't see how we could. And, I don't see how we would, when you don't show any effort.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Java is not even close to "a slow death", as you call it. The largest problem with .Net is that it runs only on Windows and most server architectures (which is where most commercial activity takes place) are not Windows.

I know, I know, .Net, in theory, can run anywhere, but for that a VM is needed and the only platform, besides Windows, where a .Net VM exists is Linux, and that in a very restricted form. The license costs for producing a VM are oppressive, and a Java VM already exists for most OSes (not to mention portable devices), so not many OS producers are really willing to create one, and no company that produces their own is willing to "give it away". So, go .Net and stay on Windows, or go Java and go everywhere (well, a lot of places, anyway), or go other languages and produce varying versions for the varying OSes.


If you are going to worry about having a "complete" skill set before you ever start looking for work, forget it. Generally however, web technologies (HTML, XML, CSS, SOAP, HTTP, SSL/TSL, probably in that order) and general DB (mainly simply SQL) are always pluses.

Edit: P.S. by problem with .Net, I mean the main problem .Net has with trying to "kill", or at least marginalise, Java, not necessarily a problem with the language itself. However, since it is advertised as "multi-platform", it is, at least, a "misleading" feature, as it …

masijade 1,351 Industrious Poster Team Colleague Featured Poster
s/\/.*$//
masijade 1,351 Industrious Poster Team Colleague Featured Poster
if (s.charAt(i)=='1') count=count*value[i];//actually i want to use this data

Okay? That is how you access a single element of an array (the reason for the brackets containing an int index). That has nothing to do with referencing the array as a whole.

Like I said, go through those tutorials.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And I said to remove the brackets.

I.E. not

int value[] = ...
// or
generate(value[]...

but rather

int[] value = ...
// and
generate(value...

And, show me the real method signature for generate, as I hope that what you showed above is simply some psedo-code fill-in. If its not pseudo code, then compare that signature with the "main" signature and tell me what you think is missing (besides static although being called from main it needs to be that too), and your local variables in main should not be static.

Have you ever done anything in Java, or are you just throwing things around from PHP, or something, and trying them in Java directly. Because the more I llok at that code, the more it looks like something copied, and then modified by someone who has no clue what they're doing.

If you are just starting then go to the official tutorials and work through those before you attempt anything else.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

remove those brackets from the end of the variable name, both when calling the method and in the declaration. In the declaration, place them after int, not after value (they both work but this way is clearer).

Edit: And I hope that that "generate" signature is not a serious attempt.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

tanx.can you explain little bit more using a example

I'm sorry, but why didn't you take the clues you'd been given, look at the API docs, and see if you could come up with something. It's usually a bit more satisfying that way, and definately more instructional and useful.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Call validate and/or repaint on the JScrollPane.

Edit: Didn't see the edit.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

getComponents and instanceof

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, is there a nextCharacter method? No? Then what about simply using next and then toCharArray on the resulting String?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You can check this article (<URL SNIPPED>HOW TO: SQL in JAVA) for the best practices on how to connect to SQLServer from Java. It also describes how pass SQL queries, pass parameters, call stored procedures etc.

Not really anything to do with it. There's not much help for it anyway, when the OP insists on doing this with scriptlets which the OP has already been warned about in no uncertain terms.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

no exeptions occur. I start the login.html, fill in the fields, click submit and I get the blan page with this one line :

" Trying Connection......Making Query"


no "processing results", no "getting data", no redirections, no nothing.

As if the compiler stops at the line, before/after the query has been made.

Because you are getting an exception, but you are catching that exception and printing the stack trace to STDERR. Like I said search your server logfiles.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You would be better off using a "DB" approach. Even if it is a "homegrown" type thing using RandomAccessFile, but better would be something like JavaDB/Derby.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Recursion.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Then provide the exception you're getting.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, what would happen if the connection (or something else) failed before the code ever got to the point where the ResultSets could be created? The would be "uninitialised", right? Since they have never had a value assigned to them, right? So, on the lines where you declare them, why don't you try assigning a value to them as well? Such as null (for a quick and dirty fix), maybe?

Local variables are not assigned any kind of value, at all, when they are defined. So, you must make certain that, regardless of the flow through the code, that the variable will have had a value assigned to it before you attempt to access that value.

Class and instance variables are automatically assigned a value when declared, but local variables are not.

P.S. get rid of all these scriplets in your JSPs, in the first place. This was the way of doing things in JEE version 1, we are now on JEE Version 6 and scriptlets have long been deprecated. They are a maintenance nightmare, and simply not scaleable, in the least (among other possible/probable problems).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

An instance variable of Class Array (which is the class behind all arrays). It is an int.

Edit: And, as noted, it represents the length of the array, and since arrays are 0-indexed, the last index of the array is length - 1, of course.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Create a 2D array where your "inputs" are the "subarrays". Then the interactions are a boolean array where true indicates that the array in that index of the "first" dimension of the 2d array should be used. Then, for the iterations, you write a triple loop outputting the first indexed arrays "current" value with the second indexed arrays "current" value, with the third indexed arrays "current" value and "X" from inside the third loop. Then, for the math, the first "value" is the length of the first indexed array times the length of the second indexed array and the second value is the length of the third indexed array and the total value is both of those values multiplied together.

Now, take that description and attempt to implement it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Post your algorithm and we will, probably, give you hints and nudges to help you increating a method that implements it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That deprecated warning also tells you what you should done (i.e. recompile with the -Xlint:deprecated option). Have you done that?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

It is because, of course, the lines like this

player1.removeElementAt(0);

where you are attempting to reference a specific element without bothering to check whether an element exists at that index. Add an if statement to check the size of the vector before each of statements i.e.

if (vec.size() > 0) vec.removeElementAt(0);

Edit: P.S. that "trimToSize" is a rather costly method that is not necessary in this context.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

As in? What exactly do you want to know?

toString is a method of Object. Object is implicitly extended (somewhere in the hierarchy chain) by every Class. So, every Class has a toString method. Usually it prints some standard String derived from Objects toString method (see the API docs to find out exactly what that is). If you want to see something else, then you need to override the toString method in your class. toString is called implicitly whenever you do a String concatenation with an Object (i.e. use "string" "+" "object") and whenever you call String.valueOf(someObject).