用Java编写一个小程序:要求从键盘输入圆的半径,求出圆的面积
package YongXingJava1import java.io.*
public class demol1{
public static void main(String[] args) {
try{
//输入流,从键盘接收数
InputStreamReader isr=new InputStreamReader(System.in)
BufferedReader br=new BufferedReader(isr)
System.out.println("请输入圆的半径:")
//从控制台读取一行数据
String a1=br.readLine()
//把string转换成float
float num1=Float.parseFloat(a1)
float result=0
float p=(float)3.14
result=p*num1*num1
if(num1<=0)
{
System.out.println("圆的半径必须大于零")
}
if(num1>0)
{
System.out.println("圆的面积为"+result)
}
} catch(Exception e)
{
e.printStackTrace()
}
}
}
public class SSS {public static void main(String[] args) {
int r = 30
for (int y = 0y <= 2 * ry += 2) {
long x = Math.round(r - Math.sqrt(2 * r * y - y * y))
long longLength = 2 * (r - x)
for (int i = 0i <= xi++) {
System.out.print(' ')
}
System.out.print('*')
for (int j = 0j <= longLengthj++) {
System.out.print(' ')
}
System.out.println('*')
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)