public class Test { public static void main(String[] args)throws Exception{ Scanner in = new Scanner(System.in); String b = in.next(); for( int i=0;i< b.length();i++){ System.out.println( b.charAt(i)+" "+(byte) b.charAt(i)); } } } 在控制台从键盘输入后,按回车即可输出。
风清淡雅
2024-11-26 08:56:37
import java.io.*; public class IO1 {public static void main(String args[]) {char c=' '; System.out.print("Enter a character please:"); try{ c=(char)System.in.read(); } catch(IOException e){}; System.out.println("ASCII:" + (int)c); } }