/* This program is for printing the triad numbers. The approach followed in this program is: We will run a loop from 100 to 333(this beacuse by the definition of triad number the third digit is 3 times first digit, if we any number greater than 333 the result will be greater than 999) , Now inside the loop we will test whether ith number has unique digits or not. If it has unique digits then we will test for 2*i and 3*i. If all the numbers have unique digits(i.e. all digits are unique)then print those numbers. */ class triad{ /* This funciton checks whether a given number has all unique digits in it or not.Here n is the no of digits in x */ public static boolean check_uniq(int x,int n) { int l,temp1,temp,k,p; temp =x; temp1 =x; l=0; for(int i=0;i<=n-1;i++) { k = temp%10; temp = temp/10; for(int j=0;j<=n-1;j++) { p = temp1%10; if(p==k) l++; temp1 = temp1/10; } temp1 = x; if(l>1) return false; l=0; } return true; } /* This is a function to check whether the given two numbers have uniq digits(i.e all the six digits are different.This problem is same as combining both the digits back to back and finding if the resultant has different digits or not. eg if x=123 and y=456 now make z =123456; now since z has all unique digits therefore x and y must have unique digits */ public static boolean check_uniq2(int x,int y) { int z; boolean flag; z = (x*1000) + y; flag = check_uniq(z,6); return flag; } public static void main(String args[]) { int i=100,j,k; boolean flag1,flag2,flag3,flag4; for(i =100;i<333;i++) { flag1 = check_uniq(i,3); if(flag1==true) { j=i*2; k=i*3; flag2=check_uniq2(i,j); flag3=check_uniq2(i,k); flag4=check_uniq2(j,k); if(flag2==true && flag3==true && flag4==true) System.out.println(i+" "+j+" "+" "+k); } } } }