本文介绍了为什么 getArea((l/3), (n - 1) 只返回空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么函数getArea返回NULL/Nothing

Why does the function getArea return NULL/Nothing

  Module Module3
  Dim noOfTriangles As Integer = (3 / 2)
  Sub main()
    Dim l As Single
    Dim n As Integer
    l = Console.ReadLine()
    n = Console.ReadLine()
    Console.WriteLine(getArea(l, n))
    Console.ReadKey()
  End Sub

  Function getArea(ByVal l As Single, ByVal n As Integer)
    Dim area As Single = 1
    If n = 0 Then
      Return Nothing
    Else
      noOfTriangles = noOfTriangles * 2
      Return (((3 ^ (1 / 2)) / 4) * (l ^ 2) + (noOfTriangles * getArea((l / 3), (n - 1))))
    End If
  End Function
End Module

推荐答案

试试这个,看看它是否让你更接近你正在寻找的东西:

Try this and see if it gets you any closer to what you're looking for:

    Module Module3
  Dim noOfTriangles As double = (3 / 2)
  Sub main()
    Dim l As Single
    Dim n As Integer
    l = Single.Parse(Console.ReadLine())
    n = Integer.Parse(Console.ReadLine())
    Console.WriteLine(getArea(l, n))
    Console.ReadKey()
  End Sub

  Function getArea(ByVal l As Single, ByVal n As Integer) as Double
    Dim area As Single = 1
    If n = 0 Then
      Return Nothing
    Else
      noOfTriangles = noOfTriangles * 2
      Return (((3 ^ (1 / 2)) / 4) * (l ^ 2) + (noOfTriangles * getArea((l / 3), (n - 1))))
    End If
  End Function
End Module

这篇关于为什么 getArea((l/3), (n - 1) 只返回空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 14:11