You are on page 1of 2

NAME: DADA AYOMIDE GREAT

COURSE: COSC 205 GROUP A

MATRIC NUMBER: 21 /2645

ASSIGNMENT SOLUTION
A. //Program to calculate the perimeter of a triangle
Import java.util.Scanner;
public class Perimeter
{
public static void main (String[]args)
{
int a, b, c;
Scanner s = new Scanner(System.in);
System.out.print("Enter the value of the first side:");
a = s.nextInt();
System.out.print("Enter the value of the second side:");
b = s.nextInt();
System.out.print("Enter the value of the third side:");
c = s.nextInt();

float Perim =(a + b + c);


System.out.println("The Perimeter of the triangle is = " +Perim);
}
}
OUTPUT
Microsoft Windows [Version 10.0.19044.2006]
(c) Microsoft Corporation. All rights reserved.
C:\Users\DADA>cd Desktop
C:\Users\DADA\Desktop>cd Cosc Assignment
C:\Users\DADA\Desktop\Cosc Assignment>javac Perimeter.java
C:\Users\DADA\Desktop\Cosc Assignment>java Perimeter
Enter the value of the first side:10
Enter the value of the second side:20
Enter the value of the third side:30
The Perimeter of the triangle is = 60.0
//PROGRAM TO COMPUTE WEIGHT OF A SPHERE
import java.util.Scanner;
public class Weight
{
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
double W,d,t,vol, rad, r1, density;
double PI = 3.142;
System.out.print("Enter the value for diameter:");
d = input.nextFloat();
rad = d/2;
System.out.print("Enter the value for thickness :");
t = input.nextFloat();
r1 = (d/2)-t;
vol= (4/3) * PI * rad*rad;
System.out.println("The volume is :" +vol);
System.out.print("Enter the value for density:");
density = input.nextFloat();
W=density*vol;
System.out.println("The weight of the sphere is : " +W);

OUTPUT
Microsoft Windows [Version 10.0.19044.2006]
(c) Microsoft Corporation. All rights reserved.
C:\Users\DADA>cd Desktop
C:\Users\DADA\Desktop>cd Cosc Assignment
C:\Users\DADA\Desktop\Cosc Assignment>javac Weight.java
C:\Users\DADA\Desktop\Cosc Assignment>java Weight
Enter the value for diameter: 10
Enter the value for thickness: 6
The volume is: 78.55
Enter the value for density: 120
The weight of the sphere is: 9426.0

You might also like