2

I want to assign complex numbers to binary values which i am doing using complex class, easily available; but when a i am appending complex numbers to string buffer, returning into a string, one complex number is taking multiple entries. How can i place 1 number to 1 entry and read afterwards? Ending string data like this "2.0+2.0i2.0-2.0i2.0+2.0i2.0-2.0i-2.0+2.0i2.0+2.0i....". Now character at 0 is '2', char at 1 is '.' and so on.. I need char at 0 to be 2.0+2.0i. and afterwards i should be able to separate real and imaginary parts of each entry.

StringBuilder symbs = new StringBuilder();
Complex s1 = new Complex(-2,-2);
Complex s2 = new Complex(+2,-2);
Complex s3 = new Complex(+2,+2);
Complex s4 = new Complex(-2,+2);
/////////////////////Symbols to vector ////////////////////
for(int i=0; i< plo.length()-1; i+=2)
{
    if(plo.charAt(i)=='1' && plo.charAt(i+1)=='0')
    {
        symbs.append(s1);
    }
    else if(plo.charAt(i)=='0' && plo.charAt(i+1)=='1')
    {
        symbs.append(s2);
    }
    else if(plo.charAt(i)=='0' || plo.charAt(i+1)=='0')
    {
        symbs.append(s3);
    }
    else if(plo.charAt(i)=='1' && plo.charAt(i+1)=='1')
    {
        symbs.append(s4);
    }
}
printComplex(symbs.toString());
0

2 Answers 2

1

"I need char at 0 to be 2.0+2.0i." thats not possible, as a char is one character.

you can append semicolons after every complex and then split for them

-1

Use Regex pattern matching similar like this [[0-9].0+[0-9].0i]+ Pass the string to the Matcher compiler and check available pattern is found on the given string. Based on that extract the value with programmatic logic to get real and imaginary parts.

Explanation on regex string

Real part

[0-9] --> it check value from 0 to 9 followed by . and followed by 0

Imaginary part

[0-9] --> it check value from 0 to 9 followed by . and followed by 0 and then by i

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.