请看注释.
import java.io.*;
class CBuy
{
    char n=0;
char money=0,storage=0;
void print()
{

System.out.print("任意-------1,>=500---------2,<500---------3");
try{ n=(char)System.in.read();
System.in.skip(2);
System.out.print("过去付款情况y---好n-----不好");

money=(char)System.in.read();
    System.in.skip(2);
System.out.print("库存情况y------够n-------不够   ");//为什么这里不能在键盘输入就执行下行了.?
storage=(char)System.in.read();

}catch(IOException e){
System.err.toString();
}
if(n=='1')
{
if(money=='y')
if(storage=='y')
System.out.println("立即发货");
else System.out.println("     款到后发货");

}
if(n=='2')
{
if(money=='n')
if(storage=='y')
System.out.println("须先付款");
else System.out.println("暂    推");
}
if(n=='3')
{
if(money=='n')
 if(storage=='y')
System.out.println("立即发货");
else System.out.println("款到后发货");
}
}
}
public class Buy {
public static void main (String[] args) {
CBuy b=new CBuy();
b.print();
}
       
}
我想通过键盘输入得到库存是否够,但是没有输入就执行下行了.怎么解决呢??
谢谢!!!

解决方案 »

  1.   

    我不太明白你这个程序的意思?
     你的程序已经没有错了?
      你自己看一下?
    import java.io.*;class Buy {
    char n = 0;
    char money = 0, storage = 0; void print() {
    System.out.print("任意-------1,> =500---------2, <500---------3 ");
    try {
    n = (char) System.in.read();
    System.in.skip(2);
    System.out.print("过去付款情况y---好n-----不好 "); money = (char) System.in.read();
    System.in.skip(2);
    System.out.print("库存情况y------够n-------不够       ");// 为什么这里不能在键盘输入就执行下行了.?
    storage = (char) System.in.read(); } catch (IOException e) {
    e.printStackTrace();
    }

    if (n == '1') {
    if (money == 'y')
    if (storage == 'y')
    System.out.println("立即发货 ");
    else
    System.out.println("           款到后发货 "); }

    if (n == '2') {
    if (money == 'n')
    if (storage == 'y')
    System.out.println("须先付款 ");
    else
    System.out.println("暂         推 ");
    }

    if (n == '3') {
    if (money == 'n')
    if (storage == 'y')
    System.out.println("立即发货 ");
    else
    System.out.println("款到后发货 ");
    }
    }
    }public class CBuy {
    public static void main(String[] args) {
    Buy b = new Buy();
    b.print();
    }
    }