0

This is my code

import java.util.*;


    public class nebucha {

    public static void main(String[] args) {

        String amac = "amamamafdfdfdfmasssmamasaaaasssamamsamsamsasssss";
        int[] data = budüzen(amac);

        System.out.println("Votes: " + Arrays.toString(data));

    }

    public static int[] budüzen(String amac) {

        int[] saysaysay = new int[3];
        for (int i = 0; i < amac.length(); i++) {
            if (amac.charAt(i) == 'a') {
                saysaysay[0]++;
            } else if (amac.charAt(i) == 'm') {
                saysaysay[1]++;
            } else if (amac.charAt(i) == 's') {
                saysaysay[2]++;
            }
        }
    }

    return saysaysay[] ;
}

i tried to compile it but i dont know why.there was a problem.im seeking a solution

Please help me.

2
  • If you could post the error that is being thrown, we might be able to help. Commented May 30, 2014 at 16:41
  • For readability purposes, I suggest putting the brackets [] directly after the type without spaces, and then have spaces after that. So instead of int []data, use int[] data. And instead of String[]args, use String[] args. Commented May 30, 2014 at 16:54

1 Answer 1

4

Instead of

return saysaysay[];

use

return saysaysay;

and put it inside the budüzen method (it's currently outside).

Here's your class, compilable, will proper indenting. The purpose of indenting is to easily see whether your statements are inside the correct {} block:

import java.util.Arrays;

public class nebucha{
    public static void main(String[]args){
        String amac="amamamafdfdfdfmasssmamasaaaasssamamsamsamsasssss";
        int []data=budüzen(amac);

        System.out.println("Votes: "+Arrays.toString(data));
    }

    public static int [] budüzen(String amac){
        int[] saysaysay = new int[3];
        for(int i=0;i<amac.length();i++){
            if(amac.charAt(i)=='a'){
                saysaysay[0]++;
            }else if(amac.charAt(i)=='m'){
                saysaysay[1]++;
            }else if(amac.charAt(i)=='s'){
                saysaysay[2]++;
            }
        }
        return saysaysay;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.