题目内容

输入一个正整数,并做以下运算:如果为偶数,除以2;如果为奇数,乘3加1。得到的结果再按上述要求运算,直到最后的结果为1,经过多少次这样的运算才得到数1。public __1__Test{public __2__void main(string[] args){System.out.println("请输入一个正整数:");Scanner sc=new Scanner(System.in);int num =3;int count = 0;while (num != 1){if (__4__){num = num / 2;}else{num=num*3+1;}__5__;}System.out.println("次数为:" + count);}}

查看答案
更多问题

程序填空题:定义一个5*5的二维数组,生成1-10随机数的随机数为数组元素赋值,先按行列输出该数组,再求主对角线及次对角线的和。public class DiagonalSum {public static void main(String[] args) {Random rnd=new Random();int[][] num=1;int sum1=0;int sum2=0;for(int i=0;i<5;i++){for(int j=0;j<5;j++){num[i][j]=2;System.out.print(num[i][j]+"\t");if(3 ){sum1+=num[i][j];}if( 4){sum2+=num[i][j];}}5 ;}System.out.println("主对角线的和为:"+sum1);System.out.println("次对角线的和为:"+sum2);}}

程序填空题:编写方法,求两个整数的最大值。调用该方法,显示变量a及b的最大值。public class MaxOfTwoNumber {public static void main(String[] args) {int a=3;int b=5;int z=;System.out.println(z);}public static2 max(int num1,int num2){int result=3 ;if(num2>result){4;}return5;}}

程序填空题:编写方法,将百分制转为等级制。调用该方法,显示78.5分的等级。public class MethodGrade {public static void main(String[] args) {1 ;}public static2getGrade( 3 ) {if (score < 0 || score > 100) {System.out.println("非法成绩");3;}if (score >= 90.0) {System.out.println('A');} else if (score >= 80.0) {System.out.println('B');} else if (score >= 70.0) {System.out.println('C');} else if (score >= 60.0) {System.out.println('D');} {System.out.println('F');}}}

程序填空题:编写多个求最大值的方法,实现方法的重载。public class MethodDemo {public static void main(String[] args) {System.out.println("3与4最大值为:" + max(3, 4));System.out.println("3.0与5.7最大值为:" + max(3.0, 5.7));System.out.println("3.0,5.7与10.4最大值为:" + max(3.0, 5.7, 10.4));}public static int max(1) {if (num1 > num2) {return num1;} else {return num2;}}public static double max(2 ) {if (num1 > num2) {return num1;} else {return num2;}}public static double3 (double num1, double num2, double num3) {return max( 4, num3);}}

答案查题题库