作者:欢颜是胖妞妞08 | 来源:互联网 | 2023-05-19 07:08
Ihavethreesortednumbers.Icanchangeonlylastoristnumbertogetthenumberinbetweentheot
I have three sorted numbers.I can change only last or ist number to get the number in between the other two.What is the maximum number of changes will i do?
我有三个已排序的数字。我只能更改最后一个或ist数字以获得其他两个之间的数字。我将做的最大更改数量是多少?
For eg:1,2,5 Ist change will be 2,3,5 Here 1 is changed to the number between 2 and 5 2nd Change will be 3,4,5 So output is 2. Can anyone tell me better implementation than below?
例如:1,2,5 Ist更改将是2,3,5这里1更改为2到5之间的数字第二更改将是3,4,5所以输出是2.任何人都可以告诉我更好的实现比下面?
void printCount() {
int a[] = {0,0,0};
Scanner in=new Scanner(System.in);
System.out.println("Enter the input");
int count1=in.nextInt();
for (int j=0;ja[2]-a[1]){
a[2]=a[0]+1;
}
else{
a[0]=a[1]+1;
}
count++;
Arrays.sort(a);
}
System.out.println(count);
}
}
1 个解决方案