storing a sentence from a file to a string java -


how can store sentence file string, , store next line, made of numbers, string?

when use hasnextline or nextline, none of works. confused.

     scanner kb = new scanner(system.in);      string secretmessage = null;      string message, number = null;      file file = new file(system.in);      scanner inputfile = new scanner(file);       while(inputfile.hasnext())      {            message = inputfile.nextline();            number = inputfile.nextline();      }        system.out.println(number + "and " + message); 

you're looping on entire file, overwriting message , number variables, , printing them once @ end. move print statement inside loop print every line.

       while(inputfile.hasnext())        {            message = inputfile.nextline();            number = inputfile.nextline();            system.out.println(number + "and " + message);        } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -