JulianJulianov

06.Methodslab-Calculate Rectangle Area

Feb 13th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. 6. Calculate Rectangle Area
  2. Create a method that calculates and returns the area of a rectangle by given width and height:
  3. Examples
  4.  
  5. Input   Output
  6. 3
  7. 4       12
  8. 6
  9. 2       12
  10. Hints
  11. 1.  After reading the input
  12. 2.  Create a method, but this time instead of typing "static void" before its name, type "static double" as this will make it to return a value of type double
  13. 3.  Invoke the method in the main and save the return value in a new variable
  14.  
  15. using System;
  16.  
  17. namespace _06CalculateRectangleArea
  18. {
  19.     class Program
  20.     {
  21.         static void Main(string[] args)
  22.         {
  23.             var width = double.Parse(Console.ReadLine());
  24.             var height = double.Parse(Console.ReadLine());
  25.             double area = GetRactangleArea(width, height);
  26.             Console.WriteLine(area);
  27.         }
  28.  
  29.         private static double GetRactangleArea(double width, double height)
  30.         {
  31.             return width * height;
  32.         }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment