0
Scanner
import java.util.Scanner ; public class num { public static void main(String[] args) { Scanner number1= new Scanner (System.in); System .out .print("enter the first number:"); int num1 =in.nextInt(); Scanner number2=new Scanner (System.in); System .out.print ("enter the second number:"); int num2=in.nextInt(); System .out .print(num1*num2 ); } } why this code doesnt work?!
3 Respostas
+ 6
Yea, also he put spaces before and after .out. and between "Scanner" and its parenthesis....
+ 4
Be careful of case-sensitivity.
+ 1
if you use
Scanner number2 = new Scanner(System.in);
then num2 should be
int num2 = number2.nextInt(); // I in int has to be capital
same for number1
usually most people use
Scanner sc = new Scanner(System.in);
and then do
int num1 = sc.nextInt();
but you can name it anything. number1 and number2 seem long
also you do not need to write number1 and number2 for Scanner, as in you don't need to specify twice, specifying once using sc or anything is fine, you can use it (sc) repeatedly throughout your code in this context.
hope this helps :)