1 1.二分查找法 2 /* 3 题目描述:给定一个数组,此数组满足两个条件,分为两段连续(递增)数字集合,第一个数肯定大于最后一个数,请返回两段数字交界处下标。 4 5 输入描述: 6 第一行 为数组中元素的数量 7 第二行 一个严格按照题目要求的数组如:70 80 90 1 20 30 8 9 输出描述: 10 返回一个int类型数字 如:3 11 示例1: 12 输入 6 13 70 80 90 1 20 30 14 输出 3 15 16 示例2: 17 输入 5 18 30 35 3 4 5 19 输出 2 20 21 */
1 2.用for循环 2 public class XiaBiao { 3 public static void main(String[] args){ 4 Scanner sc=new Scanner(System.in); 5 int a=sc.nextInt(); 6 7 int[] array=new int[a]; 8 for(int b=0;b<a;b++){ 9 array[b]=sc.nextInt(); 10 } 11 main1(array); 12 13 } 14 public static void main1(int[] array){ 15 for(int i=0;i<array.length-1;i++){ 16 if(array[i]>array[i+1]){ 17 System.out.println(i+1); 18 } 19 } 20 } 21 }
原文:https://www.cnblogs.com/zrwx/p/13854860.html