初学JAVA的一个关于屏幕输出的问题
josh 2003-08-10 12:34:10 程序如下:
1.inter.java
public class inter
{
public static void main(String args[])
{
System.out.print("Welcome to polycalc\n");
int len = args.length;
for(int i=0; i<len; i++) { if (args[i].equals("-i")) polycalc.configure(true); }
polycalc.run();
}
}
2.polycalc.java
class polycalc
{
static boolean interact=false;
static boolean end=false;
static void configure(boolean flag) {interact=flag;}
static void run()
{
while(!end)
{
if(interact) System.out.print("Poly: ");
String poly = my.read();
if(poly.equals("end")) break;
System.out.print(poly+" == not implemented yet\n\n");
}
}
}
class my
{
static String readAux(String s)
{
char c;
try{c=(char)System.in.read();}catch(Exception e) {return s;}
return c=='\n' ? s: readAux(s+c);
}
static String read() {return readAux("");}
}
程序目的:
运行程序后,如: java polycalc -i
则屏幕输出结果为长格式行:
poly: abcdedf
adcdedfg ==not implemented yet
如果输入: java polycalc (没有-i)
则屏幕输出结果为短格式行:(并且没有输出poly)
abcdef
abcdeff
not implemented yet
我的问题是:
try{c=(char)System.in.read();}catch(Exception e) {return s;}
return c=='\n' ? s: readAux(s+c);
这几句语句是做什么目的用的?
谢谢