How to make java recognize me a paragraph

3

only with a query. It's about that I'm creating a java game similar to Tamagochi from the 90's. You must have the option to create Pokemon, where you can enter the name of the Pokémon; in addition to this the player can enter an "image" of characters for his pokemon that he is creating.

my code is as follows.

        System.out.println("Ingrese el nombre de su Pokemon");
        nombreDelPokemon[contador]=scanner.next();
        System.out.println("Ingrese la imagen de su Pokemon");
        imagenDelPokemon=scanner.next();

But when I read the image variable, the Pokémon only prints the first line of the pokemon image.

the image of the pokemon is the following:

       ,     ,_
       |'\    ';;,            ,;;'
       |  '\    \ '.        .'.'
       |    '\   \  '-""""-' /
       '.     '\ /          |'
         '>    /;   _     _ \ 
          /   / |       .    ;
         <  ('";\ ()   ~~~  (/_
          ';;\  ',     __ _.-'' )
            >;\          '   _.'
            ';;\          \-'
              ;/           \ _
              |   ,"".     .' \
              |      _|   '   /
               ;    /")     .;-,
          jgs   \    /  __   .-'
                 \,_/-"'  '-'

I would like to know how to do so that Java read me the whole paragraph. Thanks

    
asked by Fuentes Villatoro Kevin Josue 13.03.2018 в 03:01
source

2 answers

2

By using only scanner.next() you are asking to save the next "word" entered, that is, you will save all the text that is before a space, if on the contrary you use scanner.nextLine() you would ask him to save the full text that is entered in the following line.

Using next() can cause your software to not work well at the time you use it, for example that you have:

   System.out.println("Ingrese el nombre de su Pokemon");
   nombreDelPokemon[contador]=scanner.next();
   System.out.println("Ingrese la imagen de su Pokemon");
   imagenDelPokemon=scanner.next();<i>

And the user enters the first question "My pokemon"

Automatically the variable nombreDelPokemon[contador] would be equal to "My" and the variable imagenDelPokemon would be equal to "Pokemon".

in the java documentation you can read a little more about this link

    
answered by 13.03.2018 / 14:50
source
1

I think the best thing for this way of working is to use the netxtLine() function, either by reading a certain number of lines (I would advise this) or by forcing the last line to have a specific code.

For the first case, I would do something like this:

int lineasImagen=12;
System.out.println("Ingrese el nombre de su Pokemon");
string nombreDelPokemon=scanner.nextLine();
System.out.println("Ingrese la imagen de su Pokemon");
List<String> imagenPokemon=new AraryList<String>();

for (int i=0;i<lineasImagen;i++){
    imagenPokemon.add(scanner.nextLine());
}

Of course, you should check that the reading of each line is correct and so on. I hope this helps you.

    
answered by 13.03.2018 в 11:42