【发布时间】:2019-06-21 18:19:35
【问题描述】:
我不确定这个编码是否没有接收到调整变量的输入并且在它完全运行之前被终止
public class Question {
int id;
String name;
String type;
double amt;
public Question(int id, String name, String type, double amt) {
this.id = id;
this.name = name;
this.type = type;
this.amt = amt;
}
public static void main(String[] args)
{ }
}
import java.util.*;
public class Answer {
public static void gettype(Question[] q,String adjust)
{
for(int i=0;i<2;i++)
{
if(q[i].getType()==adjust)
{
System.out.println(q[i].getId());
}
}}
public static void main(String[] args) {
int id;
String name,type,adjust;
double amt;
Scanner s=new Scanner(System.in);
Answer a=new Answer();
System.out.println("enter 2 car inputs");
Question[] q=new Question[2];
for(int i=0;i<2;i++)
{
id=s.nextInt();
s.nextLine();
name=s.nextLine();
type=s.nextLine();
amt=s.nextDouble();
q[i]= new Question(id,name,type,amt);
}
adjust=s.nextLine();
a.gettype(q,adjust);
}
}
在运行代码时,我能够获取汽车对象数组的输入。但之后我无法获取变量调整的值。 所以请在这方面需要帮助。 我试图简单地在构造函数端打印对象。 但无法接收将分配给 var adjust 的第 9 个输入
【问题讨论】:
-
格式和可读性差。
-
现在可以了吗?
-
你可能想参考这个:stackoverflow.com/questions/2626533 基本上你有2个主要功能,只有1个可以作为入口点。这应该可以解释提前终止
标签: java