0% found this document useful (0 votes)
22 views2 pages

Cosc Assignment For DADA AYOMIDE GREAT PDF

The document contains the code and output for two Java programs written by a student named Dada Ayomide Great for their COSC 205 course. The first program calculates the perimeter of a triangle by taking input for the lengths of three sides and adding them together. The second program calculates the weight of a sphere by taking input for the diameter, thickness, and density, then using the formula to find the volume and multiplying it by the density. Both programs output the calculation and run successfully according to the provided output.

Uploaded by

Dada Great
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Cosc Assignment For DADA AYOMIDE GREAT PDF

The document contains the code and output for two Java programs written by a student named Dada Ayomide Great for their COSC 205 course. The first program calculates the perimeter of a triangle by taking input for the lengths of three sides and adding them together. The second program calculates the weight of a sphere by taking input for the diameter, thickness, and density, then using the formula to find the volume and multiplying it by the density. Both programs output the calculation and run successfully according to the provided output.

Uploaded by

Dada Great
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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