write Java code that takes value for side of a square in jTextField1 and display its area in jTextField2.
This question is based on computer science.
Answers
Explanation:
Program
Program to Calculate Area of square.Program
* will prompt user for entering the side of the square.
*/
import java.util.Scanner;
class SquareAreaDemo {
public static void main (String[] args)
{
System.out.println("Enter Side of Square:");
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
double side = scanner.nextDouble();
//Area of Square = side*side
double area = side*side;
System.out.println("Area of Square is: "+area);
}
}
Output:
Enter Side of Square:
2.5
Area of Square is: 6.25
Program 2:
/**
* @author: BeginnersBook.com
* @description: Program to Calculate Area of square.
* No user interaction: Side of square is hard-coded in the
* program itself.
*/
class SquareAreaDemo2 {
public static void main (String[] args)
{
//Value specified in the program itself
double side = 4.5;
//Area of Square = side*side
double area = side*side;
System.out.println("Area of Square is: "+area);
}
}
Output:
Area of Square is: 20.25
Answer:
80% of the exam is always based on 1 lecture that you missed and 1 topic that you didn’t prepare.