关于字符的获得getBytes一直搞不明白!!
也就得过且过了!今天遇到一个问题
:
public class liuinput {
long f = 0;
long ff(int n) {
System.out.println(n);
if(n<0) System.out.printf("n<0,input error");
else if(n==0||n==1) f=1;
else f=ff(n-1)*n;
return f;
}
public static void main(String[] args) {
liuinput nf = new liuinput();
try {
System.out.println(nf.ff(System.in.read()));
/*从输入流中读取数据的下一个字节。返回 0 到 255 范围内的 int 字节值。
* 如果因为已经到达流末尾而没有可用的字节,则返回值 -1。
* 在输入数据可用、检测到流末尾或者抛出异常前,此方法一直阻塞。
* */
System.out.println("2".getBytes()[0]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.in是InputStreeam流!他的read方法在上面注释是api中的解释!
他返回的是字符的字节!也就是下一个字节!!
字符传输的是要找对应的AsCII码!翻译成字节数组!!
例如字符2的ASCII是十进制的50!所以相当于输入的是整数50
如果想获得int类型 那就用Scanner的nextInt方法!
假如你输入-1
他只会解析-号 他的ASCII码是45 也就是相当于输入了45
分享到:
相关推荐
java代码-System.in.read()测试
z=(char)System.in.read(); System.in.skip(2); //忽略回车换行 } catch(IOException e){} } while(z=='y'); } public static double gets(Book a){ return a.sb; } public static double getx(Book ...
编写字符界面的Java Application 接收用户输入的一个字符,并把该字符打印在屏幕上: ... ch=(char)System.in.read(); }catch(IOException e){}; System.out.println("You've entered character:"+ch); } }
tChar=(char)System.in.read(); }catch(IOException e){} } //递归函数调用求汉诺塔之解 public static void HanoiTower(int n,char a,char b,char c){ if(n==1){ System.out.print("Move disk from" +...
System.in.read(); srv.stopService(); } public class OutboundNotification implements IOutboundMessageNotification { public void process(String gatewayId, OutboundMessage msg) { System.out....
如果要使用read方法输入数据,应使用“System.in.read()”的形式。 在这个语句中,System是一个最终类,,不能用来产牛列象,它提供了 标准输入、标准输出和错误输出流;对外部定义的属性和环境变量的 访问;加载...
x=(char)System.in.read(); max = Integer.parseInt(String.valueOf(x)); a=new int[max][]; for (i=0;i;i++) { a[i]=new int[i+1]; } a[0][0]=1; for (i=1;i;i++) { a[i][0]=1; a[i][a[i].length-1]=1; for (j=1;j...
① System.Windows.Forms.Timer ② System.Timers.Timer ③ System.Threading.Timer 现分述如下: 一、System.Windows.Forms.Timer 1、基于Windows消息循环,用事件方式触发,在界面线程执行;是使用得比较多的Timer...
java 控制台输入密码显示星号 通过JNI 来调用 c++中方法 java 控制台输入密码显示星号 通过JNI 来调用 c++中方法 java 控制台输入密码显示星号 通过JNI 来调用 c++中方法 java 控制台输入密码显示星号 通过JNI 来...
The parts may be read sequentially or in arbitrary order, depend- ing on the reader’s level of knowledge and specific areas of interest. A complete discussion of digital logic and microprocessor ...
ch=System.in.read(); //该方法每次读入一个字节的内容到ch变量中。 } catch(Exception e) { } switch(ch) { case '\r': //回车时,不进行处理 break; case '\n': //换行时,将数组总的内容放进字符串中 ...
一本不错的C#书,希望对您有帮助,本书目录: ... Read This Book 1002 Index 1003 .NET Framework Class Library Documentation 1003 Search Engines 1004 Favorite Websites 1004 Summary 1004
冒泡排序 JAVA1冒泡排序 import java.io.*; class BubbleSort { static int temp=0; public static void anykey_f() { char tChar;... tChar=(char)System.in.read(); }catch (IOException e){} }
2.4.1 Basic Operating System VSB Options ........................................................... 16 BSP-Specific Optimizations ........................................................................
"Your detailed explanations are clear and backed-up with source code—and the numerous bits of humor make a dry subject very enjoyable to read." —J.D. Lindemann, network engineer, Adaptec, Inc. For ...
Git is the source code control system preferred by modern development teams. Its decentralized architecture and lightning-fast branching let you concentrate on your code instead of tedious version ...
Should you have any problems with overwriting or deleting the original file, remove attribute "read-only". 6. It is a must to run and execute file fix.reg, or else Nero applications could not be run....
In complex web applications, the low-level details of your JavaScript code can obscure the workings of the system as a whole. As a coding style, functional programming (FP) promotes loosely coupled ...