Добавить
Уведомления

Beginning Java Tutorial: 19 First Interactive Program with Scanner

Introduce the minimum of the Scanner class to create an interactive program. Import the java.util.Scanner on line 2 of the text file. (0:17) import java.util.Scanner; Explains what the program does before explaining the code. (0:54) PASTED CODE: Scanner s=new Scanner(System.in); System.out.println("Enter a value"); double x=s.nextDouble(); System.out.println("x is "+x); Briefly explain the first line of pasted code within the scope of the Beginning Java Series. (1:20) Explain the second line of pasted code (should be very familiar by now). (2:00) The purpose of this line is to let the user (the human being with thoughts and feelings) know to enter a value (he DOESN'T know he is supposed to press the ENTER key because he is not instructed.) Explains the third line of pasted code. (2:06) This line of code is used to store the user entered value into the variable x; This line is also the reason we imported the Scanner variable at the beginning. s.nextDouble() is converting the data to be read as a double type then being assigned to the x value. Explains the fourth and final line of pasted code. (2:36) This one should also be familiar. The last line prints the value of x (which is the user entered value as long as it was a valid number).

Иконка канала IT Junction
32 подписчика
12+
15 просмотров
2 года назад
12+
15 просмотров
2 года назад

Introduce the minimum of the Scanner class to create an interactive program. Import the java.util.Scanner on line 2 of the text file. (0:17) import java.util.Scanner; Explains what the program does before explaining the code. (0:54) PASTED CODE: Scanner s=new Scanner(System.in); System.out.println("Enter a value"); double x=s.nextDouble(); System.out.println("x is "+x); Briefly explain the first line of pasted code within the scope of the Beginning Java Series. (1:20) Explain the second line of pasted code (should be very familiar by now). (2:00) The purpose of this line is to let the user (the human being with thoughts and feelings) know to enter a value (he DOESN'T know he is supposed to press the ENTER key because he is not instructed.) Explains the third line of pasted code. (2:06) This line of code is used to store the user entered value into the variable x; This line is also the reason we imported the Scanner variable at the beginning. s.nextDouble() is converting the data to be read as a double type then being assigned to the x value. Explains the fourth and final line of pasted code. (2:36) This one should also be familiar. The last line prints the value of x (which is the user entered value as long as it was a valid number).

, чтобы оставлять комментарии