Java Program To Find Area And Perimeter Of A Rectangle
import java.util.*;
public class AreaAndPerimeterOfRectangle {
private static Scanner s;
public static void main(String[] args) {
double length, width, Area, Perimeter;
s = new Scanner(System.in);
System.out.print("Enter The Length Of A Rectangle = ");
length = s.nextDouble();
System.out.print("Enter The Width Of A Rectangle = ");
width = s.nextDouble();
Area = length * width;
Perimeter = 2 * (length + width);
System.out.format("Area Of The Rectangle = %.2f\n",Area);
System.out.format("Perimeter Of The Rectangle = %.2f\n", Perimeter);
}}
Java Program To Find Area And Perimeter Of A Rectangle Using OOP
import java.util.Scanner;
public class AreaAndPerimeterOfRectangle3a {
private static Scanner s;
public static void main(String[] args) {
double length, width;
s = new Scanner(System.in);
length = s.nextDouble();
System.out.print("Enter The Width Of Rectangle = ");
width = s.nextDouble();
AreaAndPerimeterOfRectangle3b ar = new AreaAndPerimeterOfRectangle3b();
ar.AreaofRectangle(length, width);
}}
AreaAndPerimeterOfRectangle3b.java:
public class AreaAndPerimeterOfRectangle3b {
double Area, Perimeter;
public void AreaofRectangle( double length, double width ) {
Area = length * width;
Perimeter = 2 * (length + width);
System.out.format("The Area Of Rectangle = %.2f\n", Area);
System.out.format("The Perimeter Of Rectangle = %.2f\n", Perimeter);
}}
Java Program To Find The Sum And Average Of Some Given Numbers
public class SumAndAverage {
public static void main(String args[]) {
int[] array = {10, 20, 30, 40, 50, 10};
int sum = 0;
for( int num : array) {
sum = sum+num;
}
double average = sum/array.length;
System.out.println("Sum of array elements is: "+sum);
System.out.println("Sum of array elements is: "+average);
}}
Java Program To Find The Sum And Average Of Numbers By User Input
import java.util.*;
public class SumAndAverage2 {
public static void main(String args[]) {
int count, i;
double sum=0;
double[] inputArray = new double[500];
Scanner n = new Scanner(System.in);
System.out.print("Total Elements: ");
count = n.nextInt();
System.out.println("Enter " + count + " Elements");
for(i = 0; i < count; i++) {
inputArray[i] = n.nextDouble();
sum = sum + inputArray[i];
}
System.out.println("Sum : " + sum);
System.out.println("Average : " + (double)sum/count);
n.close();
}}