0

I am prompting the user to enter binary digits as a String. I am trying to declare and instantiate an array of boolean elements. The array should be equal to the number of digits in the String entered by user. Not sure what I'm doing wrong here but am thinking I need to use the String length() method?

public class Binary {

    public static void main ( String [] args ) {

        Scanner scan = new Scanner(System.in);

        System.out.print("Enter some binary digits > ");
        String value = scan.nextLine();

        boolean [] booleanArray = new boolean [value];
    }
}
2
  • 4
    new boolean[value.length()] Commented May 10, 2016 at 19:36
  • your value variable is a string, but array declaration must take an int as length, @Gendarme +1 Commented May 10, 2016 at 20:00

1 Answer 1

3
public class Binary {

    public static void main ( String [] args ) {

        Scanner scan = new Scanner(System.in);

        System.out.print("Enter some binary digits > ");
        String value = scan.nextLine();


        boolean [] booleanArray = new boolean [value.length()];
        //note that initially the values stored in the array are all false
    }
}
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.