成语大全网 - 汉语词典 - java编程 求代码 4-6

java编程 求代码 4-6

public?class?Staff?{

public?static?void?main(String[]?args)?throws?Exception?{

String?hellostr?=?"Hello?World?And?You?123456!!!";

//(1)

System.out.println("length?:?"?+?hellostr.length());

//(2)

String[]?helloary?=?hellostr.split("?");

System.out.println("Split?by?spacebar:");

for?(int?i=0;i<helloary.length;i++)?{

System.out.printf("%d?%s\n",?i,?helloary[i]);

}

//(3)

int?position?=?hellostr.indexOf("1");

int?lastpostion?=?hellostr.indexOf("6")+1;

String?substr?=?hellostr.substring(position,?lastpostion);

System.out.println("substr?:?1?position?at?"?+?position?+?",?6?position?at?"?+?lastpostion);

int?intval?=?Integer.parseInt(substr);

//(4)

System.out.println("int?value?is?:"?+?intval);

//(5)

float?fval?=?Float.parseFloat(substr);

System.out.println("float?value?is?:"?+?fval);

}

}