+ 1

Java programming

Hi. I'm wondering how to write a code witch will need an input value in Java. For example, the program will sum two numbers which you should input on the begining. I don't know how to write the ''input'' part of the code. I hope you understand my question. Thank you in advance.

10th Sep 2019, 4:14 PM
Филип Пилчевић (Filip Pilcevic)
Филип Пилчевић (Filip Pilcevic) - avatar
3 odpowiedzi
+ 2
//at top import java.util.Scanner; //in a (main)method Scanner sc = new Scanner(System.in); int num1 = sc.nextInt(); int num2 = sc.nextInt();
10th Sep 2019, 4:19 PM
Anton Böhler
Anton Böhler - avatar
+ 1
A scanner can get input as a string by using the method getLine() //at top import java.util.Scanner; //in a (main)method Scanner sc = new Scanner(System.in); String num1 = sc.nextLine(); String num2 = sc.nextLine();
11th Sep 2019, 2:10 AM
Stuart Moss
Stuart Moss - avatar
0
Thanks. And what should l change if l want a text instead of number value to be in the input?
10th Sep 2019, 5:03 PM
Филип Пилчевић (Filip Pilcevic)
Филип Пилчевић (Filip Pilcevic) - avatar