Question description
Enter an int integer, and return a new integer without duplicate numbers in the order of reading from right to left.
Enter a description:
Enter an int integer
Output description:
Return a new integer without duplicate numbers in the order of reading from right to left
Input Example:
9876673
Output example:
37689
import java.util.HashSet;import java.util.Set;import java.util.Scanner;public class Main{public static int noRepeatNum(int num){String str=String.valueOf(num);int len=str.length();Set<Character> set=new HashSet<>();StringBuilder sb=new StringBuilder();for (int i=len-1;i>=0;i--){//If there is no duplication, you can add (set feature) if(set.add(str.charAt(i))){sb.append(str.charAt(i));}}return Integer.parseint(sb.toString());}public static void main(String[] args) {Scanner sc=new Scanner(System.in); while(sc.hasNext()){int num=Integer.parseint(sc.nextLine());System.out.println(noRepeatNum(num));}sc.close();}}result:
Summarize
The above is all about Java implementation extracting non-repetitive integer instances. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!