Sunday, April 24, 2005

splitting string

 

public class abc

{

public String[] split(String test)

{

int length=0,i=0,j=0,k=0,initial=0,finnal=0;

String[] temp = new String[7];

length = test.length();

for(j=0;j<length;j++)

{

if(test.charAt(j) == ';')

{

finnal=j;

temp[k] = test.substring(initial,finnal);

k++;

initial=finnal+1;

}

}

temp[k] = test.substring(initial,length);

return temp;

}

 

public static void main(String args[])

{

String s;

String[] week1 = new String[7];

abc q = new abc();

int i=0,j=0,k=0,initial=0,finnal=0,length=0;

s = "34.56;56.55;89.23;37.49;26.75;73.26;89.32";

week1 = q.split(s);

float sum = total(week1);

System.out.println("Total : " + sum);

}

 

public static float total(String test[])

{

int k=0,x=0;

float sum=0;

for(k=0;k<7;k++)

{

System.out.println(test[k]);

sum = sum + Float.parseFloat(test[k]);

}

return sum;

}

}

 

Pradyut
http://pradyut.tk
http://groups.yahoo.com/group/d_dom/
http://groups-beta.google.com/group/oop_programming
India

 

No comments: