java 字符串转为基本数据类型

 1 public class ObjectDemo {
2 public static void main(String[] args) {
3 String str1="30";
4 String str2="30.3";
5 int x=Integer.parseInt(str1);
6 float f=Float.parseFloat(str2);
7 System.out.println("整数乘方"+x+"*"+x+"="+(x*x));
8 System.out.println("小数乘方"+f+"*"+f+"="+(f*f));
9
10 }
11
12 }

你懂的。、。

posted @ 2012-03-07 21:25  谈笑风生膜法师  阅读(339)  评论(0编辑  收藏  举报