日期:2014-05-20 浏览次数:20881 次
import java.io.*; public class Czhb { public static void main(String[] args)throws Exception { int t=System.in.read(); System.out.println(t); } }
import java.util.Scanner; public class Czhb{ public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); System.out.println(t); } }
------解决方案--------------------
通用的方法:
import java.io.*; public class Test{ public static void main(String[] args){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("请输入:"); String s = br.readLine(); System.out.println(s); }catch(IOException e){ e.printStackTrace(); } } }
------解决方案--------------------
import java.io.*;
public class Test{
public static void main(String[] args){
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入:");
String s = br.readLine();
System.out.println(s);
}catch(IOException e){
e.printStackTrace();
}
}
}
同意4楼
------解决方案--------------------
没有强制转化吧?读入的默认是STRING, 而你这样是不行的。
import java.io.*; //最多算到25的阶乘 public class test { public static void main(String[] args)throws IOException { //System.out.println("输入一个数, 算"); BufferedReader buf; buf = new BufferedReader(new InputStreamReader(System.in)); String str; int x; while(true) { str = buf.readLine(); if(str.equals("quit")) break; x = Integer.parseInt(str); System.out.println(x + "的阶乘是:" + fact(x)); } } static long fact(int k) { long result = 1; for(int i = 2; i <= k; ++i) { result *= i; } return result; } }
------解决方案--------------------
这个是ASCII码值