Re: Need help to convert my C++ codes to Java with GUI

Katak wrote:
I wrote these codes below in Java and theres some problems passing the
string to do the conversion. Can anyone help me out? The c++ codes are
on the first post above. Thanks.

import java.util.Scanner;
public class BinaryToDecimal {

public static void main(String[] args) {

String bin;
result += (( bin[i] - 48)*(cubed));

Review the Javadocs for String, the type of 'bin', at

Strings are not arrays, and cannot use the square-bracket notation ([]) to represent parts of a String. A String is an object that must be accessed through its defined methods.

It seems that you are looking for String#charAt()
but be aware that character encoding can differ, and '48' might not be the magic number you're looking for. Also, what if the /i/th character is not a digit?

P.S., please use less aggressive indentation for Usenet posts. Up to four spaces (not TAB characters) per indent level is fine. You can cut back on the blank lines, too. Easier-to-read listings are easier to answer.