我已经在这几个小时,尝试不同的方法看几乎每个问题.也许我完全错了,但我觉得我的数学是正确的,但无论我输入什么数字,我都得到相同的输出.我的代码在某个地方关闭,我必须在午夜之前将其打开.
这一切都很有趣:找出一个点是否在三角形代码中.(对于初学者)
import java.util.Scanner;
public class PointsTriangle {
// checks if point entered is within the triangle
//given points of triangle are (0,0) (0,100) (200,0)
public static void main (String [] args) {
//obtain point (x,y) from user
System.out.print("Enter a point's x- and y-coordinates: ");
Scanner input = new Scanner(System.in);
double x = input.nextDouble();
double y = input.nextDouble();
//find area of triangle with given points
double ABC = ((0*(100-0 )+0*(0 -0)+200*(0-100))/2.0);
double PAB = ((x*(0 -100)+0*(100-y)+0 *(y- 0))/2.0);
double PBC …Run Code Online (Sandbox Code Playgroud) 我已经找了40多分钟试图在这个网站上找到可能与我的问题有关的答案无济于事.
我很难过.我正在尝试将程序转换为GUI.我正在使用Textpad,它在编译时告诉我变量已在main方法中定义.然后当转换为int或double时,它告诉我它找不到符号并指向我想要转换的变量.然后在我的计算过程中,它告诉我二进制运算符'*'的错误操作数类型.
import javax.swing.JOptionPane;
public class PayrollGUI {
// calculates payroll
public static void main (String [] args) {
String name = JOptionPane.showInputDialog ("Employee's Name: ");
int name = Integer.parseInt(nameString);
String hours = JOptionPane.showInputDialog ("Number of hours worked in a week (e.g., 10: ");
int hours = Integer.parseInt(hoursString);
String payRate = JOptionPane.showInputDialog ("Hourly pay rate (e.g., .6.75: ");
double payRate = Double.parseDouble(payRateString);
String federalTaxRate = JOptionPane.showInputDialog ("Federal tax witholding rate (e.g., .20: ");
double federalTaxRate = Double.parseDouble(federalTaxRateString);
String stateTaxRate = …Run Code Online (Sandbox Code Playgroud)