Programming Examples

Java program to pass an integer as argument and check whether all digits in it are unique or not


Write a program to pass an integer as argument, and check whether all digits in it are unique or not.

Solution

class Unique
{
	public static void main(int n)
	{
		int i,s=0,c=0,d,j,d1,f=0;
		for(i=n;i>0;i=i/10)
		{
			d1=i%10;
			for(j=i/10;j>0;j=j/10)
			{
				d=j%10;
				if(d==d1)
					f=1;
			}
		}
		if(f==0)
			System.out.println(“All digits are unique”);
		else
			System.out.println(“All digits are not unique”);
	}
}
Output

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz