How to scan booleans from a string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mohamad mahtabi
    New Member
    • Jan 2011
    • 3

    How to scan booleans from a string?

    I wrote this program and I want to read a binary String and write each 0 or 1 to a Boolean array.
    but I don't know why the program encounters a problem when I want to scan from String.
    Code:
    String String1;
    Boolean[] Num1 = new Boolean[32];
    int count1;
    Scanner in = new Scanner(System.in);
    String1 = in.next();
    Scanner inString1 = new Scanner(String1);
    for(count1 = 0;inString1.hasNextBoolean();count1++)
         Num1[count1] =inString1.nextBoolean();
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Why you want to scan a boolean value? I suspect your input string is something like "0001001". Consider it as string and convert it down to integer array and calculate according to value 0 or 1.

    Regards
    Dheeraj Joshi

    Comment

    Working...