Return problem in Java

Hello!

My code reads a text file and compiles it to a String. It looks for matches from ;000; to ;009; and tries to return the number sequency that was NOT found inside the String.

My return value dissappears before returning?

-Can yuo someone help me?

import java.io.*;

public class idlask7 {

static String id="";

static String findMe="";

public static void main(String[] args) throws IOException {

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

id = ideet(); // calls for method ideet()

} //main ends

public static String ideet() throws IOException{

FileInputStream toduut = new FileInputStream("Todokansio.txt");

int x = toduut.available();

byte b[] = new byte[x];

toduut.read(b);

String helprivi = new String(b);

String searchMe = helprivi;

int s=0;

for (int k = 0; k < 10 ; k++){

String findMe = ";00"+k+";";

int searchMeLength = searchMe.length();

int findMeLength = findMe.length();

boolean foundIt = false;

for (int i = 0; i <= (searchMeLength - findMeLength); i++) {

if (searchMe.regionMatches(i, findMe, 0, findMeLength)) { // line 34

foundIt = true;

System.out.println(findMe);

break;

}

}

if (!foundIt) {System.out.println("No match found."); //line 41

String id = findMe;

System.out.println(findMe);// line 43

System.out.println(id);// line 44

break;}

}

System.out.println(id);//line 47

return (id);

}

}

program result:

;000;

;000;

;001;

;001; // numbers 000 and 001 are found at line 34

;002;

No match found.//the first number not found at line 41 is 002

;002; // line43

;002; // line 44

// prints empty at line 47

[1878 byte] By [Jakepaloa] at [2007-10-3 11:09:10]
# 1
Please use code tags.What do you mean disappears?
zadoka at 2007-7-15 13:32:12 > top of Java-index,Java Essentials,Java Programming...
# 2
http://forum.java.sun.com/help.jspa?sec=formatting
CeciNEstPasUnProgrammeura at 2007-7-15 13:32:12 > top of Java-index,Java Essentials,Java Programming...
# 3
Please use code tags when posting code.Your local variable id hides the instance variable id.Mike
bellyrippera at 2007-7-15 13:32:12 > top of Java-index,Java Essentials,Java Programming...
# 4

import java.io.*;

public class idlask7 {

static String id="";

static String findMe="";

public static void main(String[] args) throws IOException {

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

id = ideet(); // calls for method ideet()

} //main ends

public static String ideet() throws IOException{

FileInputStream toduut = new FileInputStream("Todokansio.txt");

int x = toduut.available();

byte b[] = new byte[x];

toduut.read(b);

String helprivi = new String(b);

String searchMe = helprivi;

int s=0;

for (int k = 0; k < 10 ; k++){

String findMe = ";00"+k+";";

int searchMeLength = searchMe.length();

int findMeLength = findMe.length();

boolean foundIt = false;

for (int i = 0; i <= (searchMeLength - findMeLength); i++) {

if (searchMe.regionMatches(i, findMe, 0, findMeLength)) { // line 34

foundIt = true;

System.out.println(findMe);

break;

}

}

if (!foundIt) {System.out.println("No match found."); //line 41

String id = findMe;

System.out.println(findMe); // line 43

System.out.println(id); // line 44

break;}

}

System.out.println(id); //line 47

return (id);

}

}

Jakepaloa at 2007-7-15 13:32:12 > top of Java-index,Java Essentials,Java Programming...
# 5
I have no idea to How to correct this?
Jakepaloa at 2007-7-15 13:32:12 > top of Java-index,Java Essentials,Java Programming...
# 6
> I have no idea to How to correct this?Did you not read bellyripper's reply?Use a different name for the local variable.
zadoka at 2007-7-15 13:32:12 > top of Java-index,Java Essentials,Java Programming...
# 7

public static String ideet() throws IOException {

String newid = "";// <

FileInputStream toduut = new FileInputStream("Todokansio.txt");

int x = toduut.available();

byte b[] = new byte[x];

toduut.read(b);

String helprivi = new String(b);

String searchMe = helprivi;

int s = 0;

for (int k = 0; k < 10; k++) {

String findMe = ";00" + k + ";";

int searchMeLength = searchMe.length();

int findMeLength = findMe.length();

boolean foundIt = false;

for (int i = 0; i <= (searchMeLength - findMeLength); i++) {

if (searchMe.regionMatches(i, findMe, 0, findMeLength)) { // line

// 34

foundIt = true;

System.out.println(findMe);

break;

}

}

if (!foundIt) {

System.out.println("No match found."); // line 41

newid = findMe;// <

System.out.println(findMe); // line 43

System.out.println(id); // line 44

break;

}

}

System.out.println(newid); // line 47// <

return newid;// <

}

Sorry @zadok, I was a bit quick, posting the code

Message was edited by:

PhHein

PhHeina at 2007-7-15 13:32:12 > top of Java-index,Java Essentials,Java Programming...
# 8
Thank you very many!!This program is last work before graduation, so I migth need your again very soon...
Jakepaloa at 2007-7-15 13:32:13 > top of Java-index,Java Essentials,Java Programming...
# 9
> Thank you very many!!> > This program is last work before graduation, so I> migth need your again very soon...and thank you many as well!i hope i never need your though.
mkoryaka at 2007-7-15 13:32:13 > top of Java-index,Java Essentials,Java Programming...