Hey!

So I got the following assignment- Make a program which takes input from the user (6-digit number) and check how many times each digit gets repeated in the number. Java GUI was used (Netbeans 6.5.1).

This is my code. I took the input via a JTextField named tf and displayed the output on JTextArea ta.

PS- arrays not used as we haven't studied them yet

- Sorry if there are any problems with indentations/documentation.

int num= Integer.parseInt(tf.getText()); int no=num; if(num<100000) ta.setText("Invalid Input. Please Enter 6 digit number"); int n1= num%10; num=num/10; //stores last digit int n2= num%10; num=num/10; int n3= num%10; num=num/10; int n4= num%10; num=num/10; int n5= num%10; num=num/10; int n6= num%10; num=num/10; //Having stored all the digits in separate variables, we will now run loops to check the number's frequency int i1 = 0,i2 = 0,i3 = 0,i4 = 0,i5 = 0,i6=0; while(no>0) { int rem= no%10; if (rem==n1) i1++; else if (rem==n2) i2++; else if (rem==n3) i3++; else if (rem==n4) i4++; else if (rem==n5) i5++; else if (rem==n6) i6++; no=no/10; } //Printing the output below ta.append(n1+" "+"occured"+" "+i1+" "+"times"+"\n"+n2+" "+"occured"+" "+i2+" "+"times"+"\n"); ta.append(n3+" "+"occured"+" "+i3+" "+"times"+"\n"+n4+" "+"occured"+" "+i4+" "+"times"+"\n"); ta.append(n5+" "+"occured"+" "+i5+" "+"times"+"\n"+n6+" "+"occured"+" "+i6+" "+"times");

The problem is that in case of numbers like 666666, the output is -

6 occured 6 times

6 occured 0 times

6 occured 0 times

6 occured 0 times

6 occured 0 times

6 occured 0 times

How do I omit the last 5 lines? This problem occurs whenever I input a digit with any recurring digit.

What changes/additions should I make?