Input Formatting

0

I'm working on the transport problem. Only that all my entries are delimited by a ENTER I would like to

1.ler two integers (separated by space)

2. Give a ENTER

3.Read a nxm array formatted correctly;

I would also like to do this without using the Scanner class;

The code below:

package problemadotransporte;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Scanner;

    public class ProblemaDoTransporte {
        public static class Cedula{
            int noroesteDaCedula;
            int valorDaCedula;
            boolean boleano;
            public void setValues()
            {
                Scanner entrada;
                entrada = new Scanner(System.in);
                this.noroesteDaCedula=entrada.nextInt();            
            }


        }


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

         BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
         int n,m;
         n=Integer.parseInt(entrada.readLine());
         m=Integer.parseInt(entrada.readLine());
         System.out.printf("%d %d",n,m);
         Cedula[][] tableau = new Cedula[n][m];
         for(int i=0;i<n;i++)for(int j = 0;j<m;j++)tableau[i][j]=new Cedula();
         for(int i=0;i<n;i++){for(int j = 0;j<m;j++)tableau[i][j].setValues(); System.out.print("\n");}

        }

    }

The entry you are doing:

2
2
2 21 1 
1 1 

1 1 
1 1 

The input the teacher wants:

3 3
16 20 200
14 8 160
180 120 0

Do you understand something like:

inteiro inteiro
matriz de inteiroxinteiro

NOTE: I did not know how to assign a tag appropriate for this question, because they removed the TAG JAVA.

    
asked by anonymous 20.01.2017 / 18:32

1 answer

0

I found your question a bit confusing but I'll try to help you with the first part, to " read two integers (separated by space) " I modified your code a little below:

BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
    int n,m;
    String numeros[] = entrada.readLine().split(" ");
    n = new Integer (numeros[0]);
    m = new Integer (numeros[1]);
    System.out.printf("%d %d",n,m);

Instead of converting directly to int as you did I left it in String and did a split, see if it already helps you. This can take two integers separated by space.

    
20.01.2017 / 18:58