Beginner Java: Variable Scope Issue

后端 未结 1 959
醉梦人生
醉梦人生 2021-01-29 11:23

I\'m practicing some work from my java book and I\'m having an issue with getting a method to use a variable for a calculation. Please note that this is a work in progress and I

相关标签:
1条回答
  • 2021-01-29 12:10

    Please declare a variable of class and call the function from it.

        public class Geometry    
        {   
    int choice;   //the user's choice    
          double value = 0; //the value returned from the method   
          char letter;  //the Y or N from the user's decision to exit   
          double radius;  //the radius of the circle   
          double length;  //the length of the rectangle   
          double width;  //the width of the rectangle   
          double height;  //the height of the triangle   
          double base;  //the base of the triangle   
          double side1;  //the first side of the triangle   
          double side2;  //the second side of the triangle   
          double side3;  //the third side of the triangle 
          public static void printMenu()   
         {    
           System.out.println("This is a geometry calculator\nChoose what you would like to calculate"   
                              + "\n1. Find the area of a circle\n2. Find the area of a     rectangle\n3."   
                              + " Find the area of a triangle\n4. Find the circumference of a circle."   
                              + "\n5. Find the perimeter of a rectangle\n6. Find the perimeter of a triangle"   
                              + "\nEnter the number of your choice:");   
         }   
           public static void circleArea(double area)   
          {      
            System.out.println(Math.PI*Math.pow(radius, 2));   
          }   
    
          public static void main(String[] args)   
         {   
          Geometry g = new Geometry();
          g.printMenu();
        }
    }
    
    0 讨论(0)
提交回复
热议问题