Is there an equivalent method to C's scanf in Java?

前端 未结 7 1171
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 11:58

Java has the notion of format strings, bearing a strong resemblance to format strings in other languages. It is used in JDK methods like String#format() for output conversio

相关标签:
7条回答
  • 2020-12-01 12:51

    Java always takes arguments as a string type...(String args[]) so you need to convert in your desired type.

    • Use Integer.parseInt() to convert your string into Interger.
    • To print any string you can use System.out.println()

    Example :

      int a;
      a = Integer.parseInt(args[0]);
    

    and for Standard Input you can use codes like

      StdIn.readInt();
      StdIn.readString();
    
    0 讨论(0)
提交回复
热议问题