@V@ java代码笔记2010-06-12:java控制台输入各类型类实现;以及判断输入字符串里面是否有数字的两种方法:方法1:转换成字符数组;方法2:正则表达式。
2011-09-27 16:39
2141 查看
转自 : /article/4487158.html
package jay_x_20100612; import java.io.*; import java.util.regex.Pattern; public class jay_x_控制台输入各类型类实现 { public static int v = 9; public static void main(String[] args) { InputStreamReader stdin = new InputStreamReader(System.in); BufferedReader bufin = new BufferedReader(stdin); try { int i2 = Integer.parseInt(bufin.readLine()); System.out.print(i2); // 判断输入的内容里面是否有数字 String s2 = bufin.readLine(); System.out.print(s2); // 方法1:转换成字符数组,然后一个一个的比较是否含有数字 char ch3[] = s2.toCharArray(); Character ch6 = null; // char ch4[]={'1','2'}; // char ch5=ch4[1]; for (int m = 0; m < ch3.length; m++) { System.out.print(ch6.isDigit(ch3[m])); } // static boolean isDigit(char ch) // 确定指定字符是否为数字。 // static boolean isDigit(int codePoint) // 确定指定字符(Unicode 代码点)是否为数字。 // 方法2:正则表达式,比较整个字符串中是否符合数字格式 String s3 = bufin.readLine(); Pattern p = Pattern.compile("[0-9]*"); System.out.print(p.matcher(s3).matches()); // new a().a; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.print(input.readString()); System.out.print(input.readChar()); System.out.print(input.readInt()); System.out.print(input.readFloat()); System.out.print(input.readDouble()); System.out.print(v); new a().u(); System.out.print(v); } } class input { static InputStreamReader in; static BufferedReader reader; static { in = new InputStreamReader(System.in); reader = new BufferedReader(in); } static String readString() { String s = null; try { s = reader.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(0); } return s; } static char readChar() { String s = null; char ch = 'a'; try { s = reader.readLine(); ch = s.charAt(0); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(0); } return ch; } static int readInt() { String s; int i = 0; try { s = reader.readLine(); i = Integer.parseInt(s); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(0); } return i; } static float readFloat() { String s; float f = 0.0f; try { s = reader.readLine(); f = Float.parseFloat(s); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(0); } return f; } static double readDouble() { String s; double d = 0.0; try { s = reader.readLine(); d = Double.parseDouble(s); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(0); } return d; } } class a { void u() { System.out.print(new jay_x_控制台输入各类型类实现().v++); } }
相关文章推荐
- 在Java中用正则表达式判断一个字符串是否是数字的方法
- java中用正则表达式判断中文字符串中是否含有英文或者数字
- JAVA 中两种判断输入的是否是数字的方法
- java用正则表达式判断字符串中是否仅包含英文字母、数字和汉字 分类: Android JAVA 2015-06-07 21:08 31人阅读 评论(0) 收藏
- java 编写程序实现从控制台接收一个 5 位以上的整数,使用数组来判断该数字 * 是否是回文数。(例如:789987,12344321是回文数)
- java用正则表达式判断字符串中是否仅包含英文字母、数字和汉字
- java用正则表达式判断字符串中是否仅包含英文字母、数字和汉字
- Java中判断输入的字符串是否为数字常用方法
- JAVA 中两种判断输入的是否是数字的方法
- java用正则表达式判断字符串中是否仅包含英文字母、数字和汉字
- 正则表达式判断输入的字符串是否是数字
- JAVA 判断字符串是否包含某个字符 正则表达式
- 在进行C#编程时候,有的时候我们需要判断一个字符串是否是数字字符串,我们可以通过以下两种方法来实现。 【方法一】:使用 try{} catch{} 语句。 我们可以在try语句块中试图
- Java 用正则表达式判断输入的字符串是否为手机号码
- java判断输入的字符串是否为数字的方法
- 字符串要求字母、数字、特殊字符,至少有两项。正则表达式不好写,可以用这个方法实现。
- Java判断字符串是否为数字(正则表达式)
- 判断输入字符串是否等效Int32位数字的两种方法:int.TryParse(string s,out int result)和 Try Catch
- java中判断字符串是否数字的两种方法
- java 实现接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写