I am working on a basic assignment for school, namely to square a number.
And, I have written the following code;
Scanner scan = new Scanner(System.in);
System.out.print("Write a number: ");
String mataintal = scan.next();
int nr = Integer.parseInt(mataintal);
String.out.println = mataintal * mataintal;
I am attempting to multiply the number I read with my Scanner
, is there some easy way I can do that? And display the square of that number?
Yes. Call the method println
from System.out
(not String.out
which doesn't exist), you don't assign a value to it. And you multiply the int
you parsed.
String.out.println = mataintal * mataintal;
should be
System.out.println(nr * nr);