public class Task_101010007_01{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] nums=new int[10];
System.out.println("输入十个数");
for(int i = 0;i<nums.length;i++) {
nums[i]=input.nextInt();
}
System.out.println("输入一个要查找的数字:");
int findNum=input.nextInt();
for(int i = 0;i<nums.length;i++) {
if(findNum==nums[i]){
System.out.println("数组中有要查找的元素,下标是;"+i);
break;
}else if(i==nums.length-1) {
System.out.println("没有找到?是的");
}
}
}
}
-----------------------------------------------------------------------------------------
public class Task_101010007_02 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] nums=new int[10];
System.out.println("输入十个数");
for(int i = 0;i<nums.length;i++) {
nums[i]=input.nextInt();
}
int max=nums[0];
int min=nums[0];
for (int i = 1;i<nums.length;i++) {
if (nums[i]>max) {
max = nums[i];
}
if (nums[i]<min) {
min = nums[i];
}
}
System.out.println("最大值是:"+max);
System.out.println("最小值是:"+min);
}
}
--------------------------------------------------------------------------------------------
public class Task_101010007_03 {
public static void main(String[] args) {
int[] nums= {12,7,11,9,15,2};
int target=9;
boolean flag=false;
for(int i = 0;i<nums.length;i++) {
int a=nums[i];
for(int j = i+1;j<nums.length;j++) {
int b=nums[j];
if(a+b==target) {
System.out.println("找到了满足条件的数字:"+a+"--"+b+";两个数字的下标是:"+i+"--"+j);
flag=true;
break;
}
}
}
if(!flag)
System.out.println("没找到,滚!");
}
}
---------------------------------------------------------------------------------
public class Task_101010007_04 {
public static void main(String[] args) {
int[] arr= {1,3,5,7,15,9,4};
for(int i=0;i<arr.length-1;i++) {
for(int j=0;j<arr.length-1-i;j++) {
if(arr[j]>arr[j+1]) {
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
System.out.println("排序后的数组循环:");
for(int i=0;i<arr.length;i++) {
System.out.print(arr[i]+"\t");
}
System.out.println();
int num=6;
int min=0;
int max=arr.length-1;
int mid=(min+max)/2;
while(true) {
if(arr[mid]>num) {
max=mid-1;
}else if(arr[mid]<num) {
min=mid+1;
}else {
System.out.println("找到了数据,是"+mid);
break;
}
if(min>max) {
mid=-1;
break;
}
mid=(min+max)/2;
}
if(mid==-1) {
System.out.println("没有要的,滚");
System.out.println("好的");
}
}
}
----------------------------------------------------------------------
public class Task_101010007_05 {
public static int[] moveZero(int[] nums) {
int index1=0;
int index2=0;
while(index2<nums.length) {
if(nums[index2]!=0) {
nums[index1]=nums[index2];
index1++;
index2++;
}else {
index2++;
}
}
for(int i=index1;i<nums.length;i++) {
nums[i]=0;
}
return nums;
}
public static void main(String[] args) {
int[] nums= {0,1,0,3,12};
int[] newNums=moveZero(nums);
for(int i=0;i<newNums.length;i++) {
System.out.println(newNums[i]);
}
}
}
-------------------------------------------------------------------