Alright, so i have some code i have been working, i basically have done the skeleton and have looked through my Java book and scowered the web for some ideas. I'm stuck on a few thing. basically i am trying to write a program to break a code. I enter in 5 digits, there is a secret code i am trying to guess. It tells me what numbers are right. Example.. Secret number is 58104 and i guess 58024. Output is # in the first position is right, # in the 2nd position is right, so on and so fourth, my trouble is, i cant seem to think of a line id put in there even after looking through my book and asking some buddies of mine. Here is what i have so far.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package random;
import java.util.Scanner;
public class Main
{
public static void main( String [] args )
{
Scanner scan = new Scanner( System.in );
String digits = "0123456789";
String number;
int i = 0;
int count;
boolean flag = false;
do
{
System.out.print( "Enter your number > " );
number= scan.next( );
count=0;
i = 0;
if (number.length()==5)
{
while(i<5 && flag !=true)
{
char c = number.charAt( i );
if ( digits.indexOf(c) != -1 )
{
count++;
}
i++ ;
}
if (count==5)
flag = true;
else
System.out.println( "Invalid number of digits");
}
else
System.out.println( "Invalid number of characters");
} while ( flag ==false);
System.out.println( "OK");
}
}