Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.

Manisekar Chinnasami

Greenhorn
+ Follow
since Apr 07, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Manisekar Chinnasami

yup i know the exception is thrown at that point ... how can i solve that ... but when i use 'AF' as input i am getting the result ... in this case, the arraylength is 2 only ...
10 years ago
i dont find any of the array is overloaded .... but i am getting arrayoutofbound exception ...
10 years ago
the concept of the program is ... if ypu enter the input as 'ABDF' , the output should be 110101 ... for A.B,D,F which is present 1 is replaced .. for the missing c and e , 0 is added ...

the length is assigned as 6 .. so if we enter 'A' , then the output should be 100000 ... but i am getting an arrayoutofbound exception ... can you help me to find the error...

here is the program ..............

class TCheck
{
public static void main(String [] args)
{
int blen = 6;
String aString = "ABC";
int binArray[] = new int[blen];
int c,k=0,asciiVal=65,x=0;
char chArray[] = aString.toCharArray();
for(int i=0;i<chArray.length;i++)
System.out.println(chArray[i]);
for(int i =0;i<blen;i++)
{
if(chArray[x] == asciiVal)
{
binArray[k] = 1;
x++;
}
else
binArray[k] = 0;

k++;
asciiVal++;

}
for(int i=0;i<k;i++)
System.out.println(binArray[i]);
int l =0,tenPower,binaryValue=0,n=k-1;
for(int i=0;i<k;i++)
{
tenPower = (int)Math.pow(10,n);
binaryValue = binaryValue +( binArray[i] * tenPower);
n--;
}
System.out.println("binaryValue --------- "+binaryValue);
}
}
10 years ago
how can i convert an long value into binary ?? and i have to store it as long ...

(is there any way to store as binary !!! )

binVal = Integer.parseInt(Integer.toBinaryString(25));//for int it is working
10 years ago
thanks for your reply ...

finally i have got the solution for my problem ...

i have converted it to String and performed the & operation and back to binary number and stored as integer type ...

it working ....

.....
.....
bitWiseCheck = Integer.parseInt(Integer.toBinaryString((Integer.parseInt(Integer.toString(binVal[j]),2)) & (Integer.parseInt(Integer.toString(vsVal),2))));
.....
.....
10 years ago
THEN HOW COULD I DO IT WITH THE BINARY NUMBERS ???

THE ACTUAL PROBLEMS IS,

CONSIDER A BINARY NUMBER 110110101, HAVE TO CHECK BITWISE DIGIT TO ZERO OR ONE, IF IT IS ONE, THE NUMBER LEFT UNCHANGED,ELSE IF IT IS 0, THEN IT SHOULD BE CHANGED TO ONE.

IF I USE SHIFT OPERATORS WILL IT WORK ???

IS THERE ANY WAY TO INITIALISE THE NUMBERS AS BINARY ??(i think it is not there in Java)

GIVE ME A RITE SOLUTION FOR THIS ...
10 years ago
actually i m getting the values as integer ...

b = Integer.parseInt("1011111", 2)

here the value "1011111" is in String format ... but i m getting those values in the interger format ...

int c = 1011111;
int b = Integer.parseInt(c,2);

how can i convert int c to String ???
10 years ago
i need to do logical AND mulitiplication for two binary numbers ....

100 & 111 = 100

when i do that it is working for this 3 bit .... but when i go further , it is not working ...

1111111 & 100000 = 100000 ( but the output is 33792)

here is the simple program ... find where i have done the mistake ...

class Test1
{
public static void main(String [] args)
{
int a, b=1111111,c=100000,d;
a = b & c;
d = b | c;
System.out.println("& = "+a+" | = "+d);
}
}
10 years ago
yup ... you are correct, Kelvin. i didnt notice that ... thanks
10 years ago
yup .. you are correct ...
10 years ago
when i tried to compile the following program, i got an incompatible type error ... (for returning an array) ....

import java.lang.reflect.Array;

class ResizeArray
{
static int z;
public int resizeArr(int [] b,int n)
{

z = n;
b = new int[10];
b = (int[])ArrayUtils.expand(b);
return b;

}

public static Object expand(Object a)
{
Class cl = a.getClass();
if (!cl.isArray()) return null;
int length = Array.getLength(a);
int newLength = z;
Class componentType = a.getClass().getComponentType();
Object newArray = Array.newInstance(componentType, newLength);
System.arraycopy(a, 0, newArray, 0, length);
return newArray;
}

public static void main(String args[])
{
ResizeArray ra = new ResizeArray();
int a[] = {1,2,3,4,5};
System.out.println("main length "+a.length);
int d=3;
ra.resizeArr(a,d);
}
}

watz the error in it ???
10 years ago
class Test
{
public int methode()
{
int a = {1,2,3,4,5};
return a; // how to return it ??? return a[] or anyother way?
}
}

give me a solution ...
10 years ago
i can resize the array ...

COPYING ANY ARRAY IS THE OLD BUSINESS ...

here is a sample program for resizeing an array ...

import java.lang.reflect.Array;

public class ArrayResize {

public static void main (String arg[]) {

int i[] = new int[5];
for(int j=0;j<5;j++)
{
System.out.println("The i array length is " + i.length);
i = (int[])ArrayUtils.expand(i);
}
}
public static Object expand(Object a) {
Class cl = a.getClass();
if (!cl.isArray()) return null;
int length = Array.getLength(a);
int newLength = length +1; // the size of the array is incremented by 1
Class componentType = a.getClass().getComponentType();
Object newArray = Array.newInstance(componentType, newLength);
System.arraycopy(a, 0, newArray, 0, length);
return newArray;
}
}

but for resizing two arrays with different values , i feel struck ...
10 years ago
hello friends ,

In my program, i am about to resize tow arrays' size.

i could do only for one using, java.lang.reflect.Array;

i dont know how to resize two arrays with different values ie. one array should be incremented by one(that i ve done). the other should to decremented by the calculated values (might be 2 or 1).

someone guide me ...
10 years ago
HELLO FRIENDS,

FINALLY I GOT THE SOLUTION FOR THIS QUERY ...

THANKS FOR YOUR HELP ...

HERE IS THE PROGRAM ...

class Arr
{
public static void main(String[] args)
{
Arr ao = new Arr();
int a[] = {1,2,3,2,1};
int k=0;


for(int i=0;i<a.length;i++)
{
for(int j=0;j<a.length;j++)
if(i!=j)
if(a[i] == a[j])
{
k++;
break;
}
}

int b[] = new int[k];
k=0;

for(int i=0;i<a.length;i++)
{
for(int j=0;j<a.length;j++)
if(i!=j)
if(a[i] == a[j])
{
b[k] = a[i];
k++;
break;
}
}

int g,m=0;
for(int l=0;l<a.length;l++)
{
g = 0;
for(int j=0;j<b.length;j++)
{

if(a[l] == b[j])
{
break;

} g++;
if(g == b.length)
{ a[m] = a[l];
m++;
}

}
}

for(int i=0;i<m;i++)
System.out.println(a[i]);
}
}
10 years ago