I am writing a program that a user inputs a 8 digit binary number and I need to convert it to a decimal number. I am trying to figure out a way for the user to enter the binary number without any deleminators, but be able to manipulate each digit of the number seperately. Any ideas

Recommended Answers

All 3 Replies

If you read it in as a String you can then use String's toCharArray method to give you an array where each element is a single character from the String.

james, is there another way to do it without reading it as a string. Haven't gotten into array's in my class yet. I know alittle but not enough to help me

If you're not into arrays yet then maybe read as a String, then use String's charAt(int i) method to pick out each char one at a time to manipulate them, as in

String input = (get this from user input)
if (input.charAt(0) == '1') ... // first digit is a one
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.