java吧 关注:1,308,743贴子:12,884,595
  • 7回复贴,共1

求助。怎样接收从控制台输入的String类型。

只看楼主收藏回复

求助。怎样接收从控制台输入的String类型。


IP属地:河南1楼2012-04-24 18:46回复

    /*
    * To
    change this template, choose Tools | Templates
    *
    and open the template in the editor.
    */
    package javaapplication4;
    import java.io.IOException;
    /**
    *
    *
    @author dell
    */
    public class Main
    {
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) throws IOException {
    System.out.println("中国足球能否进入世界杯?");
    System.out.println("是(y) 否(n) 不一定(p)");
    char c = (char) System.in.read();
    if (c == 'y') System.out.println("Cool");
    else if (c == 'n')
    System.out.println("Bad");
    else if (c == 'p')
    System.out.println("Sorry");
    else
    System.out.println("Input
    Error");
    }
    }


    2楼2012-04-24 18:57
    回复
      2026-09-08 23:53:59
      广告
      不感兴趣
      开通SVIP免广告
      import java.io.IOException;引入包。
      char c = (char) System.in.read(); 输入字符串


      3楼2012-04-24 18:58
      回复
        System.in


        4楼2012-04-24 19:05
        回复
          Scanner sc = new Scanner(System.in);
          String str =sc.nextLine();


          5楼2012-04-24 19:17
          回复
            谢谢。我试试。


            IP属地:河南6楼2012-04-24 19:32
            回复
              我觉得最好是这样,因为是stdin,哈!
              ...
              BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in))
              ...


              7楼2012-04-24 19:33
              回复
                String Username=in.next();


                8楼2013-10-19 14:41
                回复