@@ -60,19 +60,19 @@ PS:这个字符串必须是由数字字符组成
6060| static String toString(int i) | 返回一个表示指定整数的 String 对象 |
6161| static Integer valueOf(int i) | 返回一个表示指定的 int 值的 Integer 实例 |
6262| static Integer valueOf(String s) | 返回保存指定的 String 的值的 Integer 对象 |
63- < br >
63+
6464代码示例:
6565``` java
6666package cn.itcast_03 ;
67-
68- /*
69- * int类型和String类型的相互转换
67+
68+ /*
69+ * int类型和String类型的相互转换
7070 *
71- * int -- String
72- * String.valueOf(number)
71+ * int -- String
72+ * String.valueOf(number)
7373 *
74- * String -- int
75- * Integer.parseInt(s)
74+ * String -- int
75+ * Integer.parseInt(s)
7676 */
7777public class IntegerDemo {
7878 public static void main (String [] args ) {
@@ -94,7 +94,7 @@ public class IntegerDemo {
9494 String s4 = Integer . toString(number);
9595 System . out. println(" s4:" + s4);
9696 System . out. println(" -----------------" );
97-
97+
9898 // String -- int
9999 String s = " 100" ;
100100 // 方式1
@@ -131,20 +131,20 @@ public static int parseInt(String s,int radix)
131131
132132``` java
133133package cn.itcast_04 ;
134-
135- /*
136- * 常用的基本进制转换
137- * public static String toBinaryString(int i)
138- * public static String toOctalString(int i)
139- * public static String toHexString(int i)
134+
135+ /*
136+ * 常用的基本进制转换
137+ * public static String toBinaryString(int i)
138+ * public static String toOctalString(int i)
139+ * public static String toHexString(int i)
140140 *
141- * 十进制到其他进制
142- * public static String toString(int i,int radix)
143- * 由这个我们也看到了进制的范围:2-36
144- * 为什么呢?0,...9,a...z
141+ * 十进制到其他进制
142+ * public static String toString(int i,int radix)
143+ * 由这个我们也看到了进制的范围:2-36
144+ * 为什么呢?0,...9,a...z
145145 *
146- * 其他进制到十进制
147- * public static int parseInt(String s,int radix)
146+ * 其他进制到十进制
147+ * public static int parseInt(String s,int radix)
148148 */
149149public class IntegerDemo {
150150 public static void main (String [] args ) {
@@ -153,7 +153,7 @@ public class IntegerDemo {
153153 System . out. println(Integer . toOctalString(100 ));
154154 System . out. println(Integer . toHexString(100 ));
155155 System . out. println(" -------------------------" );
156-
156+
157157 // 十进制到其他进制
158158 System . out. println(Integer . toString(100 , 10 ));
159159 System . out. println(Integer . toString(100 , 2 ));
@@ -169,7 +169,7 @@ public class IntegerDemo {
169169 System . out. println(Integer . toString(100 , 37 ));
170170 System . out. println(Integer . toString(100 , 36 ));
171171 System . out. println(" -------------------------" );
172-
172+
173173 // 其他进制到十进制
174174 System . out. println(Integer . parseInt(" 100" , 10 ));
175175 System . out. println(Integer . parseInt(" 100" , 2 ));
@@ -190,15 +190,15 @@ public class IntegerDemo {
190190
191191``` java
192192package cn.itcast_05 ;
193-
194- /*
195- * JDK5的新特性
196- * 自动装箱:把基本类型转换为包装类类型
197- * 自动拆箱:把包装类类型转换为基本类型
193+
194+ /*
195+ * JDK5的新特性
196+ * 自动装箱:把基本类型转换为包装类类型
197+ * 自动拆箱:把包装类类型转换为基本类型
198198 *
199- * 注意一个小问题:
200- * 在使用时,Integer x = null;代码就会出现NullPointerException。
201- * 建议先判断是否为null,然后再使用。
199+ * 注意一个小问题:
200+ * 在使用时,Integer x = null;代码就会出现NullPointerException。
201+ * 建议先判断是否为null,然后再使用。
202202 */
203203public class IntegerDemo {
204204 public static void main (String [] args ) {
@@ -207,12 +207,12 @@ public class IntegerDemo {
207207 Integer ii = 100 ;
208208 ii += 200 ;
209209 System . out. println(" ii:" + ii);
210-
210+
211211 // 通过反编译后的代码
212212 // Integer ii = Integer.valueOf(100); //自动装箱
213213 // ii = Integer.valueOf(ii.intValue() + 200); //自动拆箱,再自动装箱
214214 // System.out.println((new StringBuilder("ii:")).append(ii).toString());
215-
215+
216216 Integer iii = null ;
217217 // NullPointerException
218218 if (iii != null ) {
@@ -237,18 +237,18 @@ public Character(char value)
237237| isDigit(char ch) | 判断是否是数字 |
238238| char toUpperCase(char ch) | 转换成大写 |
239239| char toLowerCase(char ch) | 转换成小写 |
240- < br >
240+
241241代码示例:
242242
243243``` java
244244package cn.itcast_02 ;
245-
246- /*
247- * public static boolean isUpperCase(char ch):判断给定的字符是否是大写字符
248- * public static boolean isLowerCase(char ch):判断给定的字符是否是小写字符
249- * public static boolean isDigit(char ch):判断给定的字符是否是数字字符
250- * public static char toUpperCase(char ch):把给定的字符转换为大写字符
251- * public static char toLowerCase(char ch):把给定的字符转换为小写字符
245+
246+ /*
247+ * public static boolean isUpperCase(char ch):判断给定的字符是否是大写字符
248+ * public static boolean isLowerCase(char ch):判断给定的字符是否是小写字符
249+ * public static boolean isDigit(char ch):判断给定的字符是否是数字字符
250+ * public static char toUpperCase(char ch):把给定的字符转换为大写字符
251+ * public static char toLowerCase(char ch):把给定的字符转换为小写字符
252252 */
253253public class CharacterDemo {
254254 public static void main (String [] args ) {
@@ -275,52 +275,52 @@ public class CharacterDemo {
275275 System . out. println(" toLowerCase:" + Character . toLowerCase(' A' ));
276276 System . out. println(" toLowerCase:" + Character . toLowerCase(' a' ));
277277 }
278- }
278+ }
279279```
280280## ** 4.4 练习**
281281代码示例:统计一个字符串中大写字母字符,小写字母字符,数字字符出现的次数。(不考虑其他字符)
282282
283283``` java
284284package cn.itcast_03 ;
285-
285+
286286import java.util.Scanner ;
287-
288- /*
289- * 统计一个字符串中大写字母字符,小写字母字符,数字字符出现的次数。(不考虑其他字符)
287+
288+ /*
289+ * 统计一个字符串中大写字母字符,小写字母字符,数字字符出现的次数。(不考虑其他字符)
290290 *
291- * 分析:
292- * A:定义三个统计变量。
293- * int bigCont=0;
294- * int smalCount=0;
295- * int numberCount=0;
296- * B:键盘录入一个字符串。
297- * C:把字符串转换为字符数组。
298- * D:遍历字符数组获取到每一个字符
299- * E:判断该字符是
300- * 大写 bigCount++;
301- * 小写 smalCount++;
302- * 数字 numberCount++;
303- * F:输出结果即可
291+ * 分析:
292+ * A:定义三个统计变量。
293+ * int bigCont=0;
294+ * int smalCount=0;
295+ * int numberCount=0;
296+ * B:键盘录入一个字符串。
297+ * C:把字符串转换为字符数组。
298+ * D:遍历字符数组获取到每一个字符
299+ * E:判断该字符是
300+ * 大写 bigCount++;
301+ * 小写 smalCount++;
302+ * 数字 numberCount++;
303+ * F:输出结果即可
304304 */
305305public class CharacterTest {
306306 public static void main (String [] args ) {
307307 // 定义三个统计变量。
308308 int bigCount = 0 ;
309309 int smallCount = 0 ;
310310 int numberCount = 0 ;
311-
311+
312312 // 键盘录入一个字符串。
313313 Scanner sc = new Scanner (System . in);
314314 System . out. println(" 请输入一个字符串:" );
315315 String line = sc. nextLine();
316-
316+
317317 // 把字符串转换为字符数组。
318318 char [] chs = line. toCharArray();
319-
319+
320320 // 历字符数组获取到每一个字符
321321 for (int x = 0 ; x < chs. length; x++ ) {
322322 char ch = chs[x];
323-
323+
324324 // 判断该字符
325325 if (Character . isUpperCase(ch)) {
326326 bigCount++ ;
@@ -330,7 +330,7 @@ public class CharacterTest {
330330 numberCount++ ;
331331 }
332332 }
333-
333+
334334 // 输出结果即可
335335 System . out. println(" 大写字母:" + bigCount + " 个" );
336336 System . out. println(" 小写字母:" + smallCount + " 个" );
@@ -341,4 +341,4 @@ public class CharacterTest {
341341
342342运行结果:
343343
344- ![ Character] ( http://img.blog.csdn.net/20150829010223059 )
344+ ![ Character] ( http://img.blog.csdn.net/20150829010223059 )
0 commit comments