Rundong Huang huang784purdueedu description Program to cal
Solution
Note:
I just Deleted the this.input=input; statement.This is wrong.This always refers to the current class instance variables,constructors,methods
Here no need of using this keyword.
_________________________
SquareCalculator.java
import java.util.Scanner;
//SquareCalculator class
public class SquareCalculator {
//Method which calculates the square of a number
public int squareIt(int input)
{
//Calculating the square
int square=input*input;
return square;
}
public static void main(String[] args) {
//Creating the object for the SquareCalculator class
SquareCalculator obj=new SquareCalculator();
/* Scanner class object is used to read
* the inputs entered by the user
*/
Scanner in=new Scanner(System.in);
//Getting the input entered by the user
System.out.println(\"Enter your input :\");
int input=in.nextInt();
/* Calling the method by passing
* the user entered number as argument
*/
int square=obj.squareIt(input);
//Displaying the output
System.out.println(\"Squared input is \"+square);
}
}
______________________
Output:
Enter your input :
9
Squared input is 81
___________
Output2:
Enter your input :
12
Squared input is 144
_______________Thank You

