0

I have a question.

You have the string "1;2;3;4;5" and you want to display them one by one. the result is:

1
2
3
4
5

I have programmed this so far.

package deel_3;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class deel_3punt0 
{


    public static void main(String[] args) {

        try{
            //bijschrijven van banlist
        //FileWriter fwriter = new FileWriter("File2", true);
        //PrintWriter outputFile = new PrintWriter(fwriter);
        //lezen van de huidige lijst
        BufferedReader br = new BufferedReader(new FileReader("C:\\JavaStuff\\testyeah.txt"));
        BufferedReader br2 = new BufferedReader(new FileReader("C:\\Users\\Tim\\workspace\\deel_2\\n4d2 2.3.txt"));
        String IPF3_1 = null;

        while((IPF3_1 = br.readLine()) != null){
            //input splitten
            String arrIPF3_1 [] = IPF3_1.split(";");
            System.out.println(arrIPF3_1[1]);
            //het codewoord vinden
            String StrIPF3_1 = arrIPF3_1[1];
            //de lengte van het codewoord halen
            int mim = StrIPF3_1.length();
            System.out.println(mim);
            //bits losmaken
            String arrayinput311[]= StrIPF3_1.split("");
            System.out.println(arrayinput311[2]);
            //eerste whileloop goed
            String IPF3_1_2 = null;

            while((IPF3_1_2 = br2.readLine()) != null){
                System.out.println(IPF3_1_2);
                //input van banlist splitten
                String arrIPF3_1_2 [] = IPF3_1_2.split(";");
                //het woord voor de afstand vinden
                String StrIPF3_1_2 = arrIPF3_1_2[1];
                System.out.println(StrIPF3_1_2);
                //de lengte van het woord vinden
                int mimban = StrIPF3_1.length();
                System.out.println(mimban);
                //bits vinden
                String arrayinput312[] = StrIPF3_1_2.split("");
                System.out.println(arrayinput312[1]);


                int loop314 = 0;


                StringBuffer BFSTRING = new StringBuffer("");

                while(loop314<mim-1){


                //bits omzetten naar getallen voor de IF statement
                int getalIPF31 = Integer.parseInt(arrayinput312[loop314]);
                int getalIPF312 = Integer.parseInt(arrayinput311[loop314]);

                if(getalIPF31==getalIPF312){

                BFSTRING.append(0); 
                }

                else{
                    BFSTRING.append(1);
                }



                loop314 = loop314 +1;



                }
                double macht = 0;
                int loop315 = 0;
                double decimalewaarde = 0;
                String Bfstring = BFSTRING.toString();
                String Bfstring2 [] = Bfstring.split("");
                while(loop315<mim-1){
                    int bit_3=Integer.parseInt(Bfstring2[loop315]);

                    if(bit_3==1){
                    decimalewaarde = (decimalewaarde + Math.pow(2, macht));
                    }
                    else{

                    }

                    loop315 = loop315 +1;


                }

                System.out.println(decimalewaarde);
                FileWriter fwriter = new FileWriter("nieuwebanwoorden.txt", true);
                PrintWriter outputFile = new PrintWriter(fwriter);
                outputFile.println(decimalewaarde);
                outputFile.close();


            }







        }

        }

        catch(Exception e){
            System.out.println("error");
        }
    }

}

I have a problem in the lines

int getalIPF31 = Integer.parseInt(arrayinput312[loop314]);
int getalIPF312 = Integer.parseInt(arrayinput311[loop314]);

I have used System.out.println() for checking where the error is.

3
  • 2
    Please don't use numbers in your variable names. Commented Sep 7, 2013 at 13:50
  • 1
    Please rename your variables with readable names. Commented Sep 7, 2013 at 13:50
  • Your code is a literal mess. What is mim? Just keep it simple first. Take the String "1;2;3;4;5", split it into a String[], iterate its elements and print them. Commented Sep 7, 2013 at 13:58

1 Answer 1

1

Try this way by using replace() method and \n.

public static void main(String[] args) {

        String number = "1;2;3;4;5";
        System.out.print(number.replace(";", "\n")); //Replacing the character ";" with the character "\n"

      }

This displays the string one by one.

1
2
3
4
5
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.