自学C并发现当我为温度转换进行等式时,除非我将分数更改为小数,否则它将无效.即
tempC=(.555*(tempF-32)) 会工作,但tempC=((5/9)*(tempF-32)) 不会奏效.
为什么?
根据C Primer Plus,它应该可以工作,因为我正在使用tempC和tempF的浮子.
下面的函数从共享偏好,权重和高度中获取两个值,我使用它们来计算BMI,当我打印值的内容时,我得到我在sharedprefs中输入的值(这很好)但是当我运行时对它们进行除法运算,结果总是得到0 ..错误在哪里?
public int computeBMI(){
SharedPreferences customSharedPreference = getSharedPreferences(
"myCustomSharedPrefs", Activity.MODE_PRIVATE);
String Height = customSharedPreference.getString("heightpref", "");
String Weight = customSharedPreference.getString("weightpref", "");
int weight = Integer.parseInt(Weight);
int height = Integer.parseInt(Height);
Toast.makeText(CalculationsActivity.this, Height+" "+ Weight , Toast.LENGTH_LONG).show();
int bmi = weight/(height*height);
return bmi;
}
Run Code Online (Sandbox Code Playgroud) 我应该创建一个程序,该程序从用户那里获取分子和分母值,然后输出该分数的十进制值。但是,当我输入值时,我的输出是 0.000000。这是我的代码:
import java.util.Scanner;
import java.util.Random;
public class fraction
{
public static void main ( String [] args )
{
int num;
int den;
double result;
num = getNum();
den = getDen();
result = getResult(num, den);
printResult(num, den, result);
}
public static int getNum()
{
Scanner input = new Scanner (System.in);
int num;
System.out.print("Please enter the numerator: ");
num = input.nextInt();
return num;
}
public static int getDen()
{
Scanner input = new Scanner (System.in);
int den;
System.out.print("Please enter the …Run Code Online (Sandbox Code Playgroud)