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??

+1 vote
asked Nov 21 by bradl65 (130 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 by Peter Minarik (40,320 points)
edited Nov 22 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.
...