176k views
0 votes
Write a statement that reads an integer value from standard input into val. Assume that val has already been declared as an int variable. Assume also that stdin is a variable that references a Scanner object associated with standard input.

User Coocood
by
7.6k points

1 Answer

0 votes

// Declaring the Scanner built in class object to get input

Scanner stdin = new Scanner(System.in);

// this will flag the compiler that stdin is the variable that is used to get input

// through utility functions provided by the Scanner class

val = stdin.nextint();

// nextint() is the utility method of scanner class used to get input

User Jens Marchewka
by
6.8k points