import java.awt.*; import javax.swing.*; public class MyButton extends JFrame { public static void main(String[] args) { JFrame f = new MyButton(); JButton b = new JButton("Click me!"); f.add(b); f.setSize(200, 200); f.setVisible(true); } }
import java.lang.*; public class Square { public static void main(String[] args) { double num = 5.5; double square = Math.pow(num, 2); System.out.println("The square of " + num + " is " + square); } }This example uses the Math.pow method provided by the java.lang package to calculate the square of a number. The first argument is the number to be squared, and the second argument is the power to raise it to. In this case, we raise it to the power of 2.