gpt4 book ai didi

使用buffreader进行JAVA编程

转载 作者:太空宇宙 更新时间:2023-11-04 09:13:59 24 4
gpt4 key购买 nike

import java.io.*;  
public class Main {
public static void main(String args[])throws Exception{
String MidtermLecGrade, MidtermLabGrade;
String FinalLecGrade, FinalLabGrade;
Float MG, temp;
Float FG;
Float Average;
Float SemG;
double a =0.6;
double b = 0.4;



BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your Midterm Lecture Grade:");
MidtermLecGrade=br.readLine();
System.out.print("Enter your Midterm Lab Grade:");
MidtermLabGrade=br.readLine();

temp= (a * MidtermLecGrade) + (b*MidtermLabGrade);
MG = Float.parseFloat(temp);
System.out.println("Your Midterm Grade is :" + MG);

}
}



error: bad operand types for binary operator '*'
temp= (a * MidtermLecGrade) + (b*MidtermLabGrade);
^
first type: double
second type: String
error: bad operand types for binary operator '*'
temp= (a * MidtermLecGrade) + (b*MidtermLabGrade);
^
first type: double
second type: String
error: incompatible types: Float cannot be converted to String
MG= Float.parseFloat(temp);


^

注意:一些消息已被简化;使用 -Xdiags:verbose 重新编译以获得完整输出

最佳答案

您需要将 a 和 b 变量转换为 float 。您还需要将用户输入解析为 float 。不需要其他变量。

public static void main(String args[]) throws Exception {
String MidtermLecGrade, MidtermLabGrade;

Float temp;
float a = 0.6f;
float b = 0.4f;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your Midterm Lecture Grade:");
MidtermLecGrade = br.readLine();
System.out.print("Enter your Midterm Lab Grade:");
MidtermLabGrade = br.readLine();

temp = ((a * Float.parseFloat(MidtermLecGrade)) + (b * Float.parseFloat(MidtermLabGrade)));
System.out.println("Your Midterm Grade is :" + temp);

}

关于使用buffreader进行JAVA编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59297601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com