You are on page 1of 2

package ch4cw;

import java.util.Scanner;
import javax.swing.JOptionPane;
public class ch4cw_2 {

4));

2));

public static void main(String[] args) {


int number;
Scanner in = new Scanner(System.in);
System.out.println("Please enter an integer\n");
number = in.nextInt();
System.out.println("The square of the " + number + " is " + Math.pow(number, 2));
System.out.println("The cube of the " + number + " is " + Math.pow(number, 3));
System.out.println("The 4th power of the " + number + " is " + Math.pow(number,
String strNumber;
int number1;
strNumber = JOptionPane.showInputDialog("Enter an integer\n");
number1 = Integer.parseInt(strNumber);
System.out.println("The square of the " + number1 + " is " + Math.pow(number1,
System.out.println("The cube of the " + number1 + " is " + Math.pow(number1, 3));
System.out.println("The 4th power of the " + number1 + " is " + Math.pow(number1,

4));
String strNumber1;
int number11;
String output="";
strNumber1 = JOptionPane.showInputDialog("Enter an integer\n");
number11 = Integer.parseInt(strNumber1);
output += "The square of the " + number11 + " is " + Math.pow(number11, 2);
// output = output + "The square of the " + number + " is " + Math.pow(number, 2);
output += "\nThe cube of the " + number11 + " is " + Math.pow(number11, 3);
output += "\nThe 4th power of the " + number11 + " is " + Math.pow(number11, 4);
JOptionPane.showMessageDialog(null, output);
}
}

package ch4cw;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ch4hw_8 {


public static void main(String[] args) throws NumberFormatException, IOException
{

BufferedReader br;
System.out.println("Enter the Dimension of the Rectangle");
System.out.print("20");
br = new BufferedReader(new InputStreamReader(System.in));
float length = Float.parseFloat(br.readLine());
System.out.print("10");
br = new BufferedReader(new InputStreamReader(System.in));
float width = Float.parseFloat(br.readLine());
float area = length * width;
float perimeter = 2 * (length + width);
System.out.println("Area is "+ area);
System.out.println("Perimeter is "+perimeter);
}

You might also like