473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.
Expand|Select|Wrap|Line Numbers
  1. String String1;
  2. Boolean[] Num1 = new Boolean[32];
  3. int count1;
  4. Scanner in = new Scanner(System.in);
  5. String1 = in.next();
  6. Scanner inString1 = new Scanner(String1);
  7. for(count1 = 0;inString1.hasNextBoolean();count1++)
  8.      Num1[count1] =inString1.nextBoolean();
  9.  
Feb 28 '11 #1

✓ answered by Dheeraj Joshi

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

1 2621
Dheeraj Joshi
1,123 Expert 1GB
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
Mar 1 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: jake1138 | last post by:
Here is a function I have to get a number at the end of a string. I'm posting this in case it proves helpful to someone. Comments are welcome. int getnum(char *str) { char buffer; char *buf...
17
by: ramadu | last post by:
I know its a sin to use strings, lets skip that part... Which of these is faster and uses less memory? String.Format("SomeValue='{0}'", m_Value); or String.Concat("SomeValue='", m_Value,...
2
by: key9 | last post by:
Hi all on reading code I found these function int foo(int char); char foo(char ch_); string foo(string ch);
7
by: wizardRahl | last post by:
Hello, I'm looking to write a program that will take a user input (a sentence) and make it less sexist. For ex., User input is -> He who laughs last, laughs best. Program output -> She or he who...
1
by: kellysgirl | last post by:
Now what you are going to see posted here is both the set of instructions I was given..and the code I have written. The instructions I was given are as follows In this case, you will create...
13
by: nishit.gupta | last post by:
Is their any fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" Thnx
3
by: MLH | last post by:
Back in mid-2003, lucason posted a question about removing punctuation chars from a string. Suggested code was posted using Replace function. Could the FN below be easily modified for use with A97...
8
by: Diwa | last post by:
Hi Guys, Is there any better way than below to find an int in a string (e.g. "30" in "KFStat30A") // -------------------------------------------------------------- #include <iostream>...
21
by: yogicoder | last post by:
following is the code to accept a string from user, but i get segmentation fault as soon i have finished entering the string i.e. as soon as i press the 'enter' key. #include <stdio.h>...
5
by: buu | last post by:
I have an function that replaces some string from a huge text that I run very often... So, I wanted to speed it up... I was using String and StringBuilder. But, I was wandering should same...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.