Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我创建的表赢得了';t使用其余的代码执行 公共类BodyMassIndex扩展JFrame{ 扫描仪输入=新扫描仪(系统输入); 字符串用户名; 字符串用户_高度; 字符串用户单位重量; 双用户体重指数; 字符串用户_分类; JTable-jt; String[]column_headers={“Name”,“Height(m)”,“Weight(Kg)”,“BMI”,“Catagory”}; 字符串[][]用户统计={{user_name,user_height,user_weight,String.valueOf(user_BMI),user_Catagory}; 公共机构Massindex(){ System.out.print(“输入您的全名:”); user_name=in.nextLine(); 系统输出打印(“以磅为单位输入您的体重:”; user_weight=in.nextLine(); System.out.print(“以英寸为单位输入您的身高:”; 用户高度=in.nextLine(); 双倍高度μM=(整数.parseInt(用户高度)*0.0254); 双倍重量(千克)=(整数.parseInt(用户重量)*0.453); user_BMI=(Integer.parseInt(user_height)/(Math.pow(Integer.parseInt(user_weight),2)); 如果(用户体重指数_Java - Fatal编程技术网

Java 我创建的表赢得了';t使用其余的代码执行 公共类BodyMassIndex扩展JFrame{ 扫描仪输入=新扫描仪(系统输入); 字符串用户名; 字符串用户_高度; 字符串用户单位重量; 双用户体重指数; 字符串用户_分类; JTable-jt; String[]column_headers={“Name”,“Height(m)”,“Weight(Kg)”,“BMI”,“Catagory”}; 字符串[][]用户统计={{user_name,user_height,user_weight,String.valueOf(user_BMI),user_Catagory}; 公共机构Massindex(){ System.out.print(“输入您的全名:”); user_name=in.nextLine(); 系统输出打印(“以磅为单位输入您的体重:”; user_weight=in.nextLine(); System.out.print(“以英寸为单位输入您的身高:”; 用户高度=in.nextLine(); 双倍高度μM=(整数.parseInt(用户高度)*0.0254); 双倍重量(千克)=(整数.parseInt(用户重量)*0.453); user_BMI=(Integer.parseInt(user_height)/(Math.pow(Integer.parseInt(user_weight),2)); 如果(用户体重指数

Java 我创建的表赢得了';t使用其余的代码执行 公共类BodyMassIndex扩展JFrame{ 扫描仪输入=新扫描仪(系统输入); 字符串用户名; 字符串用户_高度; 字符串用户单位重量; 双用户体重指数; 字符串用户_分类; JTable-jt; String[]column_headers={“Name”,“Height(m)”,“Weight(Kg)”,“BMI”,“Catagory”}; 字符串[][]用户统计={{user_name,user_height,user_weight,String.valueOf(user_BMI),user_Catagory}; 公共机构Massindex(){ System.out.print(“输入您的全名:”); user_name=in.nextLine(); 系统输出打印(“以磅为单位输入您的体重:”; user_weight=in.nextLine(); System.out.print(“以英寸为单位输入您的身高:”; 用户高度=in.nextLine(); 双倍高度μM=(整数.parseInt(用户高度)*0.0254); 双倍重量(千克)=(整数.parseInt(用户重量)*0.453); user_BMI=(Integer.parseInt(user_height)/(Math.pow(Integer.parseInt(user_weight),2)); 如果(用户体重指数,java,Java,我导入了所有需要的内容并输入了上面的代码,但当它运行时,程序只会问这三个问题,然后就停止了。应该放一张桌子。不是。我如何让它工作?我不允许将JTable与扫描仪一起使用吗?我需要从用户那里获取信息,然后将其显示在表中。我已复制粘贴了您的代码。 它为我展示了一张空桌子。 原因是您的用户统计信息字段 您可以使用其他字段(用户名、用户高度等)为其赋值 请注意,提到的字段当时没有任何值,因此当您在JTable构造函数中使用用户统计信息时,它是空的。 从用户处获取数据后,应将这些值分配给它 简单地说,您可

我导入了所有需要的内容并输入了上面的代码,但当它运行时,程序只会问这三个问题,然后就停止了。应该放一张桌子。不是。我如何让它工作?我不允许将JTable与扫描仪一起使用吗?我需要从用户那里获取信息,然后将其显示在表中。

我已复制粘贴了您的代码。 它为我展示了一张空桌子。 原因是您的用户统计信息字段

您可以使用其他字段(用户名、用户高度等)为其赋值

请注意,提到的字段当时没有任何值,因此当您在JTable构造函数中使用用户统计信息时,它是空的。 从用户处获取数据后,应将这些值分配给它

简单地说,您可以在调用JTable Constructor之前复制这一行:

public class BodyMassIndex extends JFrame {
    Scanner in = new Scanner (System.in);
    
    String user_name;
    String user_height;
    String user_weight;
    Double user_BMI;
    String User_Catagory;
    
JTable jt;
    
    String[] column_headers = {"Name","Height (m)","Weight (Kg)", "BMI", "Catagory"};
    String[][] user_statistics = {{user_name, user_height, user_weight , String.valueOf(user_BMI) , User_Catagory}};
    
    public BodyMassIndex() {
        System.out.print("Enter Your Full Name: ");
        user_name = in.nextLine();
        System.out.print("Enter Your Weight in Pounds: ");
        user_weight = in.nextLine();
        System.out.print("Enter Your Height in Inches: ");
        user_height = in.nextLine();
        
        
        Double Height_M = (Integer.parseInt(user_height) * 0.0254);
        Double Weight_KG = (Integer.parseInt(user_weight) * 0.453);
        user_BMI = (Integer.parseInt(user_height)/(Math.pow(Integer.parseInt(user_weight) , 2)));
        
        if (user_BMI < 18.5) {
            User_Catagory = "Underweight";
            
        }
        
        else if (user_BMI <= 24.9 && user_BMI >= 18.5) {
            User_Catagory = "Normal or Healthy Weight";
            
        }
        
        else if (user_BMI <= 29.9 && user_BMI >= 25.0) {
            User_Catagory = "Overweight";
            
        }
        
        else {
            User_Catagory = "Obese";
            
        }
        
        jt = new JTable(user_statistics, column_headers);
        jt.setBounds(50,50,200,230);
        JScrollPane js = new JScrollPane(jt);
        this.add(js);
        this.setSize(300,400);
        this.setVisible(true);
        
        
        
    }
    
    public static void main(String[] args) {
        
        new BodyMassIndex();
        
    }
}
在我这样做之后,它为我显示了数据


我已复制粘贴了您的代码。 它为我展示了一张空桌子。 原因是您的用户统计信息字段

您可以使用其他字段(用户名、用户高度等)为其赋值

请注意,提到的字段当时没有任何值,因此当您在JTable构造函数中使用用户统计信息时,它是空的。 从用户处获取数据后,应将这些值分配给它

简单地说,您可以在调用JTable Constructor之前复制这一行:

public class BodyMassIndex extends JFrame {
    Scanner in = new Scanner (System.in);
    
    String user_name;
    String user_height;
    String user_weight;
    Double user_BMI;
    String User_Catagory;
    
JTable jt;
    
    String[] column_headers = {"Name","Height (m)","Weight (Kg)", "BMI", "Catagory"};
    String[][] user_statistics = {{user_name, user_height, user_weight , String.valueOf(user_BMI) , User_Catagory}};
    
    public BodyMassIndex() {
        System.out.print("Enter Your Full Name: ");
        user_name = in.nextLine();
        System.out.print("Enter Your Weight in Pounds: ");
        user_weight = in.nextLine();
        System.out.print("Enter Your Height in Inches: ");
        user_height = in.nextLine();
        
        
        Double Height_M = (Integer.parseInt(user_height) * 0.0254);
        Double Weight_KG = (Integer.parseInt(user_weight) * 0.453);
        user_BMI = (Integer.parseInt(user_height)/(Math.pow(Integer.parseInt(user_weight) , 2)));
        
        if (user_BMI < 18.5) {
            User_Catagory = "Underweight";
            
        }
        
        else if (user_BMI <= 24.9 && user_BMI >= 18.5) {
            User_Catagory = "Normal or Healthy Weight";
            
        }
        
        else if (user_BMI <= 29.9 && user_BMI >= 25.0) {
            User_Catagory = "Overweight";
            
        }
        
        else {
            User_Catagory = "Obese";
            
        }
        
        jt = new JTable(user_statistics, column_headers);
        jt.setBounds(50,50,200,230);
        JScrollPane js = new JScrollPane(jt);
        this.add(js);
        this.setSize(300,400);
        this.setVisible(true);
        
        
        
    }
    
    public static void main(String[] args) {
        
        new BodyMassIndex();
        
    }
}
在我这样做之后,它为我显示了数据