编程题:请勿改动程序已有内容,仅在画横线处填入适当的语句。

2025-06-21 19:26:20
推荐回答(2个)
回答1:

public static void main(String args[ ])
{
System.out.print("\n请输入一个数");
try
{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
String s=br.readLine();
/*******Found********/
int a=Integer.parseInt(s);
while(a!=1)
{
System.out.print(" "+a);
if(a%2==1)
/*******Found*********/
a=a*3+1;
else
a=a/2;
}
System.out.println(" "+a);
}
/********Found************/
catch(Exception e){}
}
}

回答2:

1: a += s;

2: a = a*3+1;

3: catch (IOException e)