ft,又遇到怪问题了 \r,你可以试着把\r转换为\\r,应该就能显示出来,那样能感觉只管点(只是自我感觉,没有实验,建议你做一下实验) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 多出来的一个字符确实是回车原因如下:在你输入完 第一次 x 之后肯定是要按一下回车键(键盘上的键)。在你输入完 第二次 y 之后,你实际输入的是 回车字符加y.你可以执行一下下边的程序.看-看结果就知道了。(以输入第二次y的值为三个字符以上为例)import java.io.*;public class temp{ public static void main (String args[]) { int xcount=0,ycount=0; char[]x=new char[50]; char[]y=new char[50]; //read x string System.out .println("please input x string"); try { int temp=System.in.read(); while (temp!=13) { x[xcount]=(char)temp; xcount++; temp=System.in.read(); } } catch(IOException e) { e.printStackTrace() ; } System.out .println(xcount); System.out .println(x); //read y string System.out.println("please input y string"); try { int temp=System.in.read(); while (temp!=13) { y[ycount]=(char)temp; ycount++; temp=System.in.read(); } } catch(IOException e) { e.printStackTrace() ; } System.out.println(ycount); System.out.println (y[0]); System.out.println (y[1]); System.out.println (y[2]); System.out.println (y[3]); }} 不是回车,是换行符,在输入完X数组后,按下回车会先产生回车符号,然后产生换行符,所以Y数组第一个变量为X数组的换行符。 在eclipse的控制台中的光标定位问题 线程同步synchronized在程序里出现多个哪个先运行? 静态方法和非静态方法有什么本质区别 不显示删除回复显示所有回复显示星级回复显示得分回复 jxl 数据库中几十万条数据写入Excel 内存溢出 Java入门问题,在void方法中打印外面的方法报错(该方法有返回值),请教原理。 JAVA连接SQL SERVER的问题?请高手帮忙解决 非常非常简单的问题! Java字符串中的代码点与代码单元 什么是双缓冲啊 今天接着散分200 多态性 菜鸟问题:矩阵乘法的这一句是不是这样写?
在你输入完 第一次 x 之后肯定是要按一下回车键(键盘上的键)。
在你输入完 第二次 y 之后,你实际输入的是 回车字符加y.
你可以执行一下下边的程序.看-看结果就知道了。(以输入第二次y的值为三个字符以上为例)
import java.io.*;
public class temp
{
public static void main (String args[])
{
int xcount=0,ycount=0;
char[]x=new char[50];
char[]y=new char[50]; //read x string
System.out .println("please input x string"); try
{ int temp=System.in.read();
while (temp!=13)
{
x[xcount]=(char)temp;
xcount++;
temp=System.in.read();
} }
catch(IOException e)
{
e.printStackTrace() ;
}
System.out .println(xcount);
System.out .println(x);
//read y string
System.out.println("please input y string");
try
{ int temp=System.in.read();
while (temp!=13)
{
y[ycount]=(char)temp;
ycount++;
temp=System.in.read();
} }
catch(IOException e)
{
e.printStackTrace() ;
} System.out.println(ycount);
System.out.println (y[0]);
System.out.println (y[1]);
System.out.println (y[2]);
System.out.println (y[3]);
}
}