Results 1 to 2 of 2
  1. #1
    nobody58 is offline Member
    Join Date
    Mar 2010
    Posts
    14
    Rep Power
    0

    Default is there anyway to replace java.IO

    hi I made this hang man game

    but my teacher doesn't want me to use java.IO

    or buffer reader

    this is my code

    Java Code:
    import java.io.*;
    public class HangmanGame{ 
     static BufferedReader br    
     = new BufferedReader(new InputStreamReader(System.in));  
     public static void main(String[] args) 
     throws IOException{    
         System.out.println("What is the word I'm thinking of? you got a guess limit of 12 (guess the word letter by letter)");      
         boolean playAgain;   
          
             playGame();     
             String input = br.readLine();  
            System.out.println("you lost"); 
        } 
        static void playGame() 
        throws IOException{   
            String word[] = {"apple", "orange", "computer", "jokes", "testing", "names", "laptop", "java", "bluej", "paper","stone","rock","world"};   
            char Guesses;   
            String Word, Save;   
            char[] Words, visible;   
            int letters, letterguesses;   
            Word = word[(int)(Math.random() * word.length)];   
           Save = Word;   
            for(char alphabet= 'a'; alphabet <= 'z'; alphabet++){  
                Word = Word.replace(alphabet,'*');  
            }   
            letters = Word.length(); 
            System.out.println("The word is " + letters + " letters long"); 
            System.out.println(Word);    
            Words = Save.toCharArray();   // saving the word   
            visible = Word.toCharArray(); // show the guesses letters in place of the stars *********  (e.g. c*m*u*t*r (computer))  
            letterguesses = 0;   
            while (letterguesses < 12 ) { 
                System.out.println();    
                System.out.print ("What is you guess? > "); 
                String i = br.readLine();      
                if (i.length() < 1){    
                    i = "?";      
                }      
                Guesses = i.charAt(0);  
                boolean inWord = false;    
                for (int j = 0; j < Words.length; j++) { 
                    if (Words[j] == Guesses){       
                        inWord = true;       
                        visible[j] = Guesses;      
                    }     
                }    
                for (int j = 0; j < Words.length; j++) {   
                    System.out.print(visible[j]);    
                }     
                System.out.println(); 
                if ((new String(visible)).indexOf('*') == -1){  
                    break;    
                }   
                if (inWord == false){  
                    System.out.println(" You've entered an incorrect wrong"); 
                    letterguesses++;    
                }    
            }  
            if ((new String(visible)).equals(Save)){ 
                System.out.println("you win");  
    {
    System.exit(0);
    }
    
            }    
            else{  
                System.out.println("The word I'm thinking of is: " + Save);  
            }  
        }
    }

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    830
    Rep Power
    6

    Default

    Use Scanner class for getting the inputs...so that you can Bypass io
    Ramya:cool:

Similar Threads

  1. Replies: 2
    Last Post: 08-18-2008, 02:59 PM
  2. [SOLVED] how to replace exact string in java
    By pankaj_salwan in forum New To Java
    Replies: 22
    Last Post: 07-08-2008, 09:28 AM
  3. Java 1.4 api replace for javax.activity ( java 1.5)
    By agrawal27 in forum Advanced Java
    Replies: 0
    Last Post: 12-17-2007, 07:41 PM
  4. Using a replace method...
    By paul in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •