该计划的想法是建立一个用户名,要求我指定为双打的3个变量,并使用这些变量来计算各种等式。我的第一个错误是在线; System.out.print(“trapazoid的区域是”)+(h *(a + b)/ 2); 我收到一个'错误:不是声明',箭头指向第一个加号。非常感谢任何帮助。
import java.util.Scanner;
public class LineberryCorey
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
String userName;
double a;
double b;
double h;
System.out.print ("What is your first name?");
userName = stdIn.nextString();
System.out.print ("Alright, " + userName + ". Give me a number.");
a = stdIn.nextDouble();
System.out.print ("give me another number.");
b = stdIn.nextDouble();
System.out.print ("Give me one more number.");
h = stdIn.nextDouble();
System.out.print ("using the date you provided...");
System.out.print ("The area of a trapazoid is ") + (h * (a + b)/2);
System.out.print ("The surface area of a box is ") + (2 * ((a * b) + (a * h) + (b * h)));
System.out.print ("The surface area of a sphere with radius ") + a + (" is ") + (4 * MATH.PI * (a * a));
System.out.print ("The volume of a sphere with radius ") + b + (" is ") + (4 * MATH.PI * (b * b * b) / 3);
System.out.print ("The volume of a spherical cap is ") + (MATH.PI * (h * h) * (3 * a - h) / 3);
System.out.print ("The volume of a frustum is ") + (MATH.PI * h * ((a * a) + (a * b) + (b * b)) / 3);
System.out.print ("The volume of a torus with radii of ") + a + (" and ") + b + (" is "((MATH.PI * MATH.PI) *
(((a + b) * (b - a)) * ((a + b) * (b - a))) / 4);
}
}
答案 0 :(得分:0)
更正所有System.out.print()语法:
//correct the code:
System.out.print ("The area of a trapazoid is" + (h * (a + b)/2));
System.out.print ("The surface area of a box is " + (2 * ((a * b) + (a * h) + (b * h))));
System.out.print ("The surface area of a sphere with radius " + a + " is " + (4 * MATH.PI * (a * a)));
System.out.print ("The volume of a sphere with radius " + b + " is " + (4 * MATH.PI * (b * b * b) / 3));
System.out.print ("The volume of a spherical cap is " + (MATH.PI * (h * h) * (3 * a - h) / 3));
System.out.print ("The volume of a frustum is " + (MATH.PI * h * ((a * a) + (a * b) + (b * b)) / 3));
为什么要连接sysout
语句
(" is ")// here parenthesis not required.