+ 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.
3 Réponses
+ 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();
+ 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();
0
Thanks. And what should l change if l want a text instead of number value to be in the input?