题目:从扑克牌中随机的选5张牌,大小王可以表示任何数,验证五张牌是否为顺子
package com.bupt.acm; import java.util.Arrays; import java.util.Scanner; /** * 扑克牌的顺子 * @author dell * */ public class Main24 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=5; int[] numb=new int[n]; while(scanner.hasNext()){ for(int i=0;i<n;i++){ numb[i]=scanner.nextInt(); } Arrays.sort(numb); int count0=0; int countdiff=0; for(int i=0;i<n;i++){ if(numb[i]==0){ count0++; }else{ if(i>0&&numb[i-1]!=0){ countdiff+=numb[i]-numb[i-1]-1; } } } System.out.println("count0:"+count0+"; countdiff:"+countdiff); if(countdiff>count0){ System.out.println("不连续"); }else{ System.out.println("连续"); } } } }