@V@ java代码笔记2010-06-12:java控制台输入各类型类实现;以及判断输入字符串里面是否有数字的两种方法:方法1:转换成字符数组;方法2:正则表达式。
来源:互联网 发布:混凝土抗风柱计算软件 编辑:程序博客网 时间:2024/05/17 21:56
转自 : http://jayxigua.iteye.com/blog/691025
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++); }}
- @V@ java代码笔记2010-06-12:java控制台输入各类型类实现;以及判断输入字符串里面是否有数字的两种方法:方法1:转换成字符数组;方法2:正则表达式。
- java中判断字符串是否数字的两种方法(在java中用正则表达式)
- java判断输入的字符串是否为数字的方法
- java中判断字符串是否数字的两种方法
- java中判断字符串是否数字的两种方法
- JAVA 中两种判断输入的是否是数字的方法
- JAVA 中两种判断输入的是否是数字的方法
- JAVA 中两种判断输入的是否是数字的方法
- java判断输入的是否为数字的方法
- 正则表达式来判断输入0-100的数字,保留两位小数方法的两种方法
- Java把字符串中的数字删除的方法和判断字符串里面是否有汉字的方法
- Java把字符串中的数字删除的方法和判断字符串里面是否有汉字的方法
- Java中判断输入的字符串是否为数字常用方法
- Java从控制台获取输入的两种方法
- Java控制台输入方法
- java:控制台输入方法
- java控制台输入的几种方法
- java 判断是否是数字的两种方法
- 技术人员如何转型?
- TCP/IP(六)
- ASP.NET网站实现中英文转换(本地化资源)
- linux c mysql例子
- 关于用英文做Presentation
- @V@ java代码笔记2010-06-12:java控制台输入各类型类实现;以及判断输入字符串里面是否有数字的两种方法:方法1:转换成字符数组;方法2:正则表达式。
- 测试游戏时音效出现问题的原因
- TCP/IP(七)
- VS2008(SP1)资源编译错误:fatal error RC1015: cannot open include file 'afxres.h'.
- MySQL客户工具和API
- 软件架构应该做些什么
- jquery ajax 异步导致赋值不起作用
- TCP/IP(八)
- 详解哈希表及分析HashMap的实现