Java User Input and Difference between readInt and nextInt?

前端 未结 2 787
后悔当初
后悔当初 2021-01-29 15:19

What is wrong with this?

import java.io.*;

class TUI{

    public static void main(String[] args) {

        System.out.println(\"Enter the two numbers:\");
            


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 15:56

    readInt is used with datainputstream class. nextInt with scanner class and you need to create a scanner object inorder to get input values. i.e

    java.util.Scanner obj=new java.util.Scanner(System.in);
          int x=obj.nextInt();
    

    Objective of both is the same to read integer values.

提交回复
热议问题