0

I am doing an exercise in which I have to create a two-dimensional array in java whose data is going to be entered with data type float. The code I made for the array with int data is:

package Facturacion;

import java.util.Scanner;

public class matriz1 {

public static void main(String[] args) {
    Scanner input=new Scanner(System.in);
    float[][] matriz;
    int n,m,i,j;
    System.out.print(" ");
    n=input.nextInt();
    m=4;
    
    matriz=new float[n][m];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            System.out.print("MATRIX ["+i+"]["+j+"]=  ");
            matriz[i][j]=input.nextFloat();
        }
    }
           
}

}

The problem I have is that when I enter the float data to create the matrix, the code breaks and I don't know how to fix it. What if I can do is that the result of the print of the matrix shows the data in float, but for this case it was not useful

MATRIX [0][0]=  1.0
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextFloat(Scanner.java:2496)
at Facturacion.reto1.main(reto1.java:20)

0 Answers0