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.


Relevant Pages

  • RE: EXCEL: How to scan text reversed (like ACCESS: InStrRev)?
    ... Thanks for your followup comment on Ron's use of StrReverse, ... It was my first post ever in the Community. ... reverse a string - a better solution than the udf I offered. ... If you need to reverse the text, you could try another udf for that as well: ...
  • Re: Whats wrong with the syntaz of this statement?
    ... Dirk Goldgar responded to your first post over an hour ago. ... string and store it somewhere (preferably a memo field, ... Dim rec_mail As DAO.Recordset ...
  • RE: SUMPRODUCT - Count Various criteria in same column (exclude ot
    ... The LEFTfunction returns the leftmost portion of a string, ... number of characters you specify. ... Although my first post said 18, ... "EricB" wrote: ...
  • Re: Error 6, Overflow in VBA code
    ... Sheepishly provided (as I should have done in my first post) is the code ... string to encrypt (sInput) is passed: ... ' if the string length is not a multiple of 8 ... ' put numeric representation of first 4 characters of the input ...
  • Re: Problem reading Chr(0) from random file...
    ... See my first post. ... tried to read it from the file, the character what I'm getting is terminated ... when it reaches the null string. ... > That's just because message box will truncate strings. ...