这是我的代码.由于某种原因,我的BMI计算不正确.当我在计算器上检查输出时:(10/((10/100)^2)))我得到1000,但在我的程序中,我得到5.我不确定我做错了什么.这是我的代码:
import javax.swing.*;
public class BMI {
public static void main(String args[]) {
int height;
int weight;
String getweight;
getweight = JOptionPane.showInputDialog(null, "Please enter your weight in Kilograms");
String getheight;
getheight = JOptionPane.showInputDialog(null, "Please enter your height in Centimeters");
weight = Integer.parseInt(getweight);
height = Integer.parseInt(getheight);
double bmi;
bmi = (weight/((height/100)^2));
JOptionPane.showMessageDialog(null, "Your BMI is: " + bmi);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试用条件编写嵌套连接查询.
我现在的查询是:
Event.joins(:store => :retailer).where(store: {retailer: {id: 2}})
Run Code Online (Sandbox Code Playgroud)
哪个输出以下SQL:
SELECT "events".* FROM "events" INNER JOIN "stores" ON "stores"."id" = "events"."store_id" INNER JOIN "retailers" ON "retailers"."id" = "stores"."retailer_id" WHERE "store"."retailer_id" = '---
:id: 2
'
Run Code Online (Sandbox Code Playgroud)
还有以下错误:
SQLite3::SQLException: no such column: store.retailer_id: SELECT "events".* FROM "events" INNER JOIN "stores" ON "stores"."id" = "events"."store_id" INNER JOIN "retailers" ON "retailers"."id" = "stores"."retailer_id" WHERE "store"."retailer_id" = '---
:id: 2
'
Run Code Online (Sandbox Code Playgroud)
它告诉我没有列store.retailer_id,但是,我可以运行以下查询,它将正常工作:
Event.first.store.retailer_id
Event Load (0.2ms) SELECT "events".* FROM "events" ORDER BY "events"."id" ASC LIMIT 1 …Run Code Online (Sandbox Code Playgroud) 我有一个FooBar带有三列的model():
Foo -> String
Bar -> JSON
Baz -> String
Run Code Online (Sandbox Code Playgroud)
我想为这个模型创建一个表单
Bar具有以下默认属性: {zing: {}, zaz: {}, laz: {}}
我想有以下输入:
f.input :foo
f.input :zing
f.input :zaz
f.input :laz
f.input :baz
Run Code Online (Sandbox Code Playgroud)
我尝试使用fields_for并传入每个键并将其转换为符号:
bar.each do |k,v|
f.input k.to_sym
end
Run Code Online (Sandbox Code Playgroud)
但我得到的错误是FooBar有未定义的方法:zaz
任何想法将不胜感激,谢谢.
当用户输入整数时,程序运行平稳,但当用户输入最后有小数的数字时,程序崩溃.
这些是我得到的错误:
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:458)
at java.lang.Integer.parseInt(Integer.java:499)
at BMI.main(BMI.java:11)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import javax.swing.*;
public class BMI {
public static void main(String args[]) {
int height; // declares the height variable
int weight; // declares the weight variable
String getweight;
getweight = JOptionPane.showInputDialog(null, "Please enter your weight in Kilograms"); // asks user for their weight
String getheight;
getheight = JOptionPane.showInputDialog(null, "Please enter your height in Centimeters"); // asks user for their height
weight = Integer.parseInt(getweight); // stores their weight
height = …Run Code Online (Sandbox Code Playgroud) 我的简短代码中不断出现错误.我不确定有什么问题,能帮帮我吗?
码:
import java.util.Scanner;
public class Driver {
private int age, carValue, tickets;
public getInfo(){
Scanner in = new Scanner(System.in);
System.out.println("Enter Age: ");
age = in.nextInt();
System.out.println("Enter Car Value: ");
carValue = in.nextInt();
System.out.println("Enter the number of tickets you have: ");
tickets = in.nextInt();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的主要内容:
class Main
{ public static void main(String args[])
{
Driver john;
john = new Driver();
john.getInfo();
}
}
Run Code Online (Sandbox Code Playgroud)
我的错误是:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method getInfo() is undefined for …Run Code Online (Sandbox Code Playgroud)