gpt4 book ai didi

java - 需要帮助修复此程序

转载 作者:行者123 更新时间:2023-11-30 03:22:18 27 4
gpt4 key购买 nike

我应该如何编写程序,以便它接受用户的输入并将其分配给变量age,然后运行代码?

public class Callone 
{
public void print_det()
{
int age = y;
if(age > 25)
System.out.println("Not Valid");
else
System.out.println("Valid");
}
public static void main(String[] args)throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader (System.in));
System.out.println("Enter the age of the applicant");
int y = Integer.parseInt(br.readLine());
Callone c = new Callone();
c.print_det();
}
}

最佳答案

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Callone {

public void print_det(int y)
{
int age = y;
if(age > 25)
System.out.println("Not Valid");
else
System.out.println("Valid");
}
public static void main(String[] args)throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the age of the applicant");
int y = Integer.parseInt(br.readLine());
Callone c = new Callone();
c.print_det(y);
}
}

在 Eclipse 中运行时,在停止用户输入数字并按 Enter 键时停止控制台,您应该看到输出

关于java - 需要帮助修复此程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31056817/

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