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;


    System.out.print( "Enter your number > " );
    number= scan.next( );

    i = 0;

 if (number.length()==5)
      while(i<5 && flag !=true)

              char c = number.charAt( i );

             if ( digits.indexOf(c) != -1 )


           i++ ;


        if (count==5)

            flag = true;

         System.out.println( "Invalid number of digits");

 System.out.println( "Invalid number of characters");

} while ( flag ==false);

    System.out.println( "OK");

7 Years
Discussion Span
Last Post by musthafa.aj

you asking that you guess number in your mind that will be identified by the computer...

else what?...:|

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.