我现在正在开发一个程序,它可以分割,添加等等,但是,即时消息也可以为其他人使用,因此,问题通常也包含字母。我可以执行哪些代码,以便我的程序忽略字符,并只专注于数字?忽略字符
编辑
进口静态文件java.lang.System.out; import java.util.Scanner;
公共类三叉{ 公共静态无效的主要(最终字符串ARGS []){
final Scanner first = new Scanner(System.in);
out.print("Enter the first number: ");
final int First = first.nextInt();
final Scanner second = new Scanner(System.in);
out.print("Enter the second number: ");
final int Second = second.nextInt();
final Scanner third = new Scanner(System.in);
out.print("Enter the third number: ");
final int Third = third.nextInt();
numFactors(First);
}
}
好的解决方案在这里:http://stackoverflow.com/questions/1102891/how-to-check-a-string-is-a-numeric-type-in-java – sikander 2012-03-28 21:34:37
你可以使用'Character.isDigit( c)'如果给定的字符是数字? – twain249 2012-03-28 21:37:23