Computer Science, asked by darshagarwal20066, 26 days ago

A number is said to be a "Unique number" if the digits within the number are not repeated . Write a program IN JAVA ALONG WITH VARIABLE DESCRIPTION to accept a number. Check and print whether the number is a Unique number or not .

Sample Input: 54263

Sample Output: It is a Unique number

Sample Input: 3272

Sample Output: It is not a Unique number

Answers

Answered by Kalihacker
1

import java.util.*;

public class Main {

public static void main(String[] args) {

int tot=0;

ArrayList<Character> obj=new ArrayList();

System.out.print("Input the number: ");

Scanner scan=new Scanner(System.in);

int num=scan.nextInt();

String str_num=Integer.toString(num);

int len=str_num.length();

for (int i=0;i<len;i++) {

obj.add(str_num.charAt(i));

}

for (int i=0;i<len;i++) {

char a=str_num.charAt(i);

for (int j=0;j<obj.size();j++) {

if (a==obj.get(j)) {

tot=tot+1;

} else {

continue;

}

}

}

if (len==tot) {

System.out.println("It is a unique number");

} else {

System.out.println("It is not a unique number");

}

}

}

Similar questions
Chemistry, 26 days ago