Java-圆柱体积 [英] Java- volume of a cylinder

查看:67
本文介绍了Java-圆柱体积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要在问题陈述上提供一些帮助。

•使用main方法创建A类

•在同一工作区创建类b

•在B类中,创建一个静态不返回任何名为ay的值的方法,该值具有双重参数,即Pi,radius和height。该方法应打印出圆柱体积(Pi * R ^ 2 * H)

•在A类中访问B类中的pi变量并将其设置为3.142

•仍在A类中编写一组语句,允许用户输入一个值并将其设置为等于变量radius。重复相同的语句集并将新输入的值设置为B类中的变量高度。

•在main方法中调用方法a





让我告诉你直到我到达的地方:

i需要知道如何在A类中访问变量Pi并将其设置为3.142。这就是我所面临的挑战



我尝试过:



Hello, i need a bit of assistance on a problem statement.
•Create a class A with the main method
•Create class b in the same work space
•In class B, create a static method that doesn’t return any value called ay that has thee double arguments i.e. Pi, radius and height. The method should print out the volume of a cylinder (Pi*R^2*H)
•In class A access the pi variable in class B and set it equal to 3.142
•Still in class A write a set of statements that will allow the user to input a value and set it equal to the variable radius. Repeat the same set of statements and set the new inputted value to the variable height in class B.
•Call the method ay in the main method.


Let me show you till where i reached:
i need to know how to access variable Pi in class A and set it to 3.142. That is the challenge i am having

What I have tried:

package six;

class A {
     
     
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
}
 class B{
	public static void ay (double Pi, double Radius, double Height){
		System.out.println(Pi*Radius*Radius*Height);
	}
}

推荐答案

引用:

需要知道如何在A类中访问变量Pi并将其设置为3.142

need to know how to access variable Pi in class A and set it to 3.142



简单:


Simple:

B.ay(3.142, 10.0, 10.0);


您需要先写出A类的剩余部分。使用扫描仪获取用户输入,并保存变量值。在B类中创建一个名为Pi的变量,可以从外部访问。您可以从 Trail:学习Java语言(The Java™Tutorials)中获得更多想法[< a href =https://docs.oracle.com/javase/tutorial/java/index.html\"target =_ blanktitle =New Window> ^ ]。
You need to write the remainder of class A first. Use a Scanner to get user input, and save the variable values. Create a variable in class B called Pi that can be accessed from outside. You can get more ideas from Trail: Learning the Java Language (The Java™ Tutorials)[^].


你的主要功能将如下所示

Your main function will be something like below
public static void main(String[] args) {
	loop(more to process) {
		read radius
		read height
                call B.ay(pi, radius, height);
		do you want to process more?
	}
}





那将是你的算法



That's going to be your algorithm


这篇关于Java-圆柱体积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆