gpt4 book ai didi

java - 需要从接收扫描仪的对象/方法调用并打印它

转载 作者:行者123 更新时间:2023-12-02 05:08:46 24 4
gpt4 key购买 nike

我需要能够填写“姓名、年龄、学校 GPA 和收到的最高字母成绩”。然而,我在执行这个看似简单的任务时遇到了困难。请帮忙!!

package schoolinfo;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;


public class SchoolInfo {
void stu(String name, String
age, String school, double gpa, char letter){

System.out.println("You, " + name +", are " + age+ " years old and go to " + school + " Where you have a gpa of " + gpa + "and have recieved a highest letter grade of " + letter);

}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
SchoolInfo student = new SchoolInfo();
Scanner scan = new Scanner(System.in);
boolean onoff = true;

while(onoff){
String countAge = " ";
String countGPA = " ";
String countName = " ", countSchool = " ";
String countLetter = " ";
String first;
first = scan.nextLine();
if(first.equals("quit")){
break;
}


first = scan.nextLine();
countName = first.substring(0, first.indexOf(" ", 2));
countAge = first.substring(first.indexOf(" ", 2), first.indexOf(" ", 2));
countSchool = first.substring(first.indexOf(" ", first.indexOf(" ", 2)), first.indexOf(" ", 2));
countGPA = scan.nextDouble();
countLetter = scan.next().charAt(first.lastIndexOf(" ") + 1);
System.out.println("test");
student.stu(countName, countAge, countSchool, countGPA, countLetter);

}
}

}

我想我需要添加更多详细信息才能发布此内容,但请帮忙!!!蒂亚!!

最佳答案

您传递给 stu 的参数与您在类中声明的参数不匹配。

void stu(String name, String
age, String school, double gpa, char letter)

在 main 中,您已将变量声明为 String

String countAge = " ";
String countGPA = " ";
String countName = " ", countSchool = " ";
String countLetter = " ";

但是您随后尝试以 double 形式检索 countGPA 的输入。

countGPA = scan.nextDouble();

您可能应该将 countGPA 声明为 double 并将 countLetter 转换为 char 或更改类方法将其作为 String 接受。

关于java - 需要从接收扫描仪的对象/方法调用并打印它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27532597/

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