-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsqr.java
More file actions
25 lines (19 loc) · 713 Bytes
/
sqr.java
File metadata and controls
25 lines (19 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//this program prints square of the number using two methods(multiplication & maths function)
import java.util.Scanner;
public class sqr {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = scanner.nextInt();
int square = number * number;
System.out.println("The square of " + number + " is: " + square);
scanner.close();
}
}
//public class SquareNumber {
//public static void main(String[] args) {
//int number = 5;
//double square = Math.pow(number, 2); // Note: Math.pow returns a double
//System.out.println("The square of " + number + " is: " + square);
//}
//}