Java multiplier table! Help me find a mistake.



  • Created two files (i.e. need to learn and develop PLOs). Compiler's fighting a mistake in line 12 in two files.

    UPD: int tablex[] на ArrayList tablex = new ArrayList();

    Compiler makes a mistake main.java:

    Error:(16, 31) java: incompatible types: int[] cannot be converted to java.util.ArrayList
    Error:(18, 32) java: bad operand types for binary operator '>'
      first type:  java.util.ArrayList
      second type: int
    Error:(19, 62) java: array required, but java.util.ArrayList found
    Error:(19, 84) java: array required, but java.util.ArrayList found
    

    Compiler makes a mistake main.java:

    Error:(17, 19) java: not a statement
    Error:(17, 21) java: ';' expected
    

    a2.java:

    package table;
    

    public class a2 {
    public static int[] create(int x) {
    int[] tablex = new int[9];
    for (int i = 1; i<10; i++) {
    tablex[i] = x * i;
    tablex[i+1] = i; //12 строка
    }
    return tablex;
    }
    }


    UPD: main.java:

    package table;

    import java.util.ArrayList;
    import static java.lang.reflect.Array.getLength;

    public class main {
    public static void main(String[] args) {
    //ArrayList tablex = new ArrayList();
    int tablex[] = null;
    a2 aa = new a2();
    for (int i = 2; i < 9; i++) {
    tablex[] =aa.create(i);//17 строка
    ArrayList tablex = new ArrayList();
    int first_int = i;
    for (i = 0; tablex > i; i++) {
    System.out.println(first_int + " * " + tablex[i + 1] + " = " + tablex[i]);
    }
    }
    }
    }



  • int[] tablex = new int[9];
       for (int i = 1; i<10; i++){
           tablex[i] = x * i;
           tablex[i+1] = i; //12 строка
       }
    

    You have a size of 9, and you start with 1 and 10 in the cycle, the indexes in the mass start from 0 to 0. length -1♪ When you want to turn to i+1 and current i = 10, you' beyond the range. Look closely at the indices.

    ArrayList cannot be converted to type int.[] We can create an ArrayList based on a mass.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2