importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args ){Scanner sc =newScanner(System.in);String imput =sc.next();String arr[]= imput.split("");int[] a =newint[arr.length];
sc.close();for(int i =0; i<a.length; i++){
a[i]=Integer.parseInt(arr[i]);}int temp;for(int i =0; i<a.length-1; i++){for(int j = i+1; j<a.length; j++){if(a[i]<a[j]){
temp = a[j];
a[j]= a[i];
a[i]= temp;}}}for(int i =0; i<a.length; i++){System.out.print(a[i]);}}}
判断一个数是否是“相邻位不重复数”
importjava.util.Scanner;publicclassMain{publicstaticvoid main (String[] args){Scanner sc =newScanner(System.in);int num = sc.nextInt();int count=0;int n = num;while(n !=0){
count ++;
n /=10;}int abc[]=newint[count];for(int i=0; i<count; i++){
abc[i]= num%10;
num /=10;}boolean flag =false;for(int j=0; j<abc.length-1; j++){if(abc[j]== abc[j+1]){
flag =true;break;}}if(!flag){System.out.println(true);}else{System.out.println(false);}}}
学生成绩类排序
importjava.util.TreeSet;importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args){Scanner sc =newScanner(System.in);TreeSet<Student> stus =newTreeSet<>();while(sc.hasNext()){String name = sc.next();String id = sc.next();int chinese = sc.nextInt();int math = sc.nextInt();int english = sc.nextInt();
stus.add(newStudent(name,id,chinese,math,english));}
sc.close();for(Student stu :stus){System.out.println(stu);}}}classStudentimplementsComparable<Student>{privateString name;privateString id;privateint chinese;privateint math;privateint english;publicStudent(){}publicStudent(String name,String id,int chinese ,int math,int english){this.name = name;this.id = id;this.chinese = chinese;this.math = math;this.english = english;}publicintgetSum(){return chinese+math+english;}publicintgetChinese(){return chinese;}publicintgetMath(){return math;}publicintgetEnglish(){return english;}publicStringgetId(){return id;}publicStringtoString(){return name+", "+id+", "+getSum()+", "+chinese+", "+math+", "+english;}publicintcompareTo(Student o){Student stu =(Student) o;int num1 = stu.getSum()-this.getSum();int num2 =(num1==0? stu.getChinese()-this.getChinese(): num1);int num3 =(num2==0? stu.getMath()-this.getMath(): num2);int num4 =(num3==0? stu.getEnglish()-this.getEnglish(): num3);int num5 =(num4==0?this.id.compareTo(stu.getId()): num4);return num5;}}
使用集合存储和遍历
importjava.util.ArrayList;importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args){Scanner sc =newScanner(System.in);ArrayList<Student> list =newArrayList<>();while(sc.hasNext()){String name = sc.next();String id = sc.next();int chinese = sc.nextInt();int math = sc.nextInt();int english = sc.nextInt();Student stu =newStudent(name,id,chinese,math,english);
list.add(stu);}for(int i=0;i<list.size();i++){System.out.println(list.get(i));}}}classStudent{privateString name;privateString id;privateint chinese;privateint math;privateint english;publicStudent(){}publicStudent(String name,String id,int chinese ,int math,int english){this.name = name;this.id = id;this.chinese = chinese;this.math = math;this.english = english;}publicintgetSum(){return chinese+math+english;}publicStringtoString(){return name+", "+id+", "+getSum()+", "+chinese+", "+math+", "+english;}}
找一组数据中最大的"相邻位不重复数"
importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args){Scanner sc =newScanner(System.in);int max =0;
lable:while(sc.hasNextInt()){int num = sc.nextInt();char[] ch =String.valueOf(num).toCharArray();for(int i=0;i<ch.length-1;i++)if(ch[i]== ch[i+1]){continue lable;}if(max<num){
max = num;}}System.out.println(max);}}
找出一组正整数中的最大值及其最大位import java.util.Scanner;public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int max=0; while(sc.hasNextInt()){ int num=sc.nextInt(); if(ma