PDA

View Full Version : Write a Java program for money/reps



MongolPup
04-23-2009, 11:38 AM
Alright I need a simple java program (Intro to Java) written ASAP. Paypal and reps are in order.

Question:

"Find the calss StringBuffer in java API, and find appropriate methods in the class to do the following:

Finding all matches of a substring in a given string, the substring and the string must be inputted from the keyboard.

The output should be the starting index numbers of the matches. For example, if the substring is "ab" and the string is "xabbnabz" then the output is 1 and 5, the indices of the two matches from left."

I KNOW we have some java monsters in our midsts.

blacknightteg
04-23-2009, 11:39 AM
fuuuuuuuuuuck that.

MongolPup
04-23-2009, 11:40 AM
fuuuuuuuuuuck that.

x2. It'd be easy for someone who knows the ins and outs though.

blacknightteg
04-23-2009, 11:42 AM
true lol.

Ed
04-23-2009, 11:42 AM
man 3 years ago when i was taking java hardcore i could do it but i forgot it all. if you cant get it done by tonight i'll give it a try.

MongolPup
04-23-2009, 11:43 AM
man 3 years ago when i was taking java hardcore i could do it but i forgot it all. if you cant get it done by tonight i'll give it a try.

Need it by 1:45 lolz...

Ed
04-23-2009, 11:57 AM
ah. good luck.

Atlblkz06
04-23-2009, 12:09 PM
I forgot java but... can you input the string as an array, loop through blocks of letters to find the query?

say the input block is "bobwehadababyitsaboy" (length 20)
You are searching for "had".
had = 3 length.

make the program loop through the array from 1 to 20-3.
Select 3 letters and see if those 3 match "had".
Record the positions where you get a match and your output will be "5"

Hope that helps.

man
04-23-2009, 12:10 PM
if you woulda posted up earlier it would be no problem. I'll see what I can do

Atlblkz06
04-23-2009, 12:14 PM
Is it done yet fcman? Tick tock! lol

MongolPup
04-23-2009, 12:18 PM
Got it gentlemen, thanks anyway. If any of you were working on it, here's one of the things it could look like:

import javax.swing.JOptionPane;

public class nurvspecii {
public static void main(String args[]) {
String subString = JOptionPane.showInputDialog(null, "Sub String: ");
String mainString = JOptionPane.showInputDialog(null, "Main String: ");

StringBuffer x = new StringBuffer(mainString);

for(int i=0; i<=mainString.length()-subString.length(); i++) {

String temp = x.substring(i,(i+subString.length()));
if (temp.equals(subString)) {
JOptionPane.showMessageDialog(null, i);
}
}
}
}

AirMax95
04-23-2009, 12:55 PM
Fuuuckkkkkk Java......although I am relearning it, lol.

VB anyone? lol