Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

WHY .class Error??

+4 votes
asked Nov 21, 2021 by bradl65 (160 points)

Why do I get an error  in the for loop??

error: '.class' expected  at the variable i

public class Main {

    private static char[] [] readSecret(String nachricht, int n, int m) {

        char[][] chars = new char[n][m];

    For (int i = 0; i < n; i++){

        For (int j = 0; j < m; j++){

           chars[i] [j] = nachricht.charAt(i*n + j);

        }

   }

      return chars;

      }

      

  public static void main(String[] args) {

          if (args.length != 5)

      {

System.out.println ("ERROR: Zu wenig Würfel");

return;

      }

          System.out.println (readSecret("alle meine Entchen", 3,6));

      }

  }

1 Answer

0 votes
answered Nov 22, 2021 by Peter Minarik (86,040 points)
edited Nov 22, 2021 by Peter Minarik

Generally it is a good idea to share

  • what language you're using
  • what is your program supposed to do
  • what do you think the problem is
  • what are your inputs when you have the problem

Here's how I've fixed your code:

For is spelled with lower case f, not upper case F. Most programming languages is case sensitive.

Also, your indentation is all over the place. You should fix it to make your code more readable.

public class Main
{
    private static char[][] readSecret(String nachricht, int n, int m)
    {
        char[][] chars = new char[n][m];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
               chars[i][j] = nachricht.charAt(i * n + j);
            }
        }

        return chars;
    }

    public static void main(String[] args)
    {
        if (args.length != 5)
        {
            System.out.println ("ERROR: Zu wenig Würfel");
            return;
        }

        System.out.println(readSecret("alle meine Entchen", 3, 6));
    }
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...