Time:09-27
CodePudding user response:
post code
then you can create a constructor, Public among (a, b, c) Then the method to no1 (), don't need parameters, Call parameters in no1, came from the parameters of the constructor provides
Quote: refer to 4th floor are nu month god reply: then you can create a constructor, Public among (a, b, c) Then the method to no1 (), don't need parameters, Call parameters in no1, came from the parameters of the constructor provides This constructor I won't use
I know this is is, but the main method to write not
Class Program {The static void Main (string [] args) {Console. WriteLine (" the length of three sides respectively: "); The length of the Console. WriteLine (" a "); Double a=double. Parse (Console. ReadLine ()); The length of the Console. WriteLine (" b "); Double b=double. Parse (Console. ReadLine ()); The length of the Console. WriteLine (" c "); Double c=double. Parse (Console. ReadLine ()); Double area=new Triangle (a, b, c). GetArea (); Console. WriteLine (" the area of the triangle {0} : ", area); Console.ReadLine(); } } Public class Triangle {Public double SideA {get; The set; } Public double SideB {get; The set; } Public double SideC {get; The set; } Public Triangle () {} Public Triangle (double sideA, double sideB, double sideC) {SideA=SideA; SideB=SideB; SideC=SideC; } Public double GetArea () {If (SideA + SideB & gt; SideC & amp; & SideA + SideC & gt; SideB & amp; & SideB + SideC & gt; SideA) {Double s; Double area; S=(SideA + + SideC SideB)/2; Area=math.h Sqrt (s * (s - SideA) * (s - SideB) * (s - SideC)); return s; } The else {Console. WriteLine (" error!" ); return 0; } } }
Page link:https//www.codepudding.com/net/37098.html