simple hangman code in java

A very simple hangman code in java
--------------------------------------------------------------------------------------------------------------------------
package assignment;
import java.util.*;



class game
{
String word[]={"appreciate","arithmetic","artificial","earthquake","economical","elasticity",
"population","positively","screenplay","toothpaste"};

String mword2;
String t;
int temp;
int random()
{
Random rn = new Random(); //to generate random no. between 1-9
int rand = rn.nextInt(9)+1;
return rand;
}

String chooseword()  //to choose a random word
{   String mword;
int r=random();
mword=word[r];
return mword;
}
String modword()  // to put "_" in word
{  int t2;

t=chooseword();
String st=t;
for(int i=0;i<5;i++)
{

t2=random();
   st=change(t2,st);

}
return st;
}
String change(int t2,String s) //part of modword(),to put "_"
{ String st;
st=s.substring(0, t2-1)+"_"+s.substring(t2,s.length());
return st;
}

}//end game
public class ass2 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
int marks = 0;
game g=new game();
String s1,s2,s3;
System.out.println("enter ");
for(int i=0;i<5;i++)
{
s2=g.modword();
System.out.println(s2);
s3=sc.next();
if(s3.equals(g.t))
marks= marks + 5;
else
marks=marks-1;
System.out.println(marks);
}
System.out.println("marks-> " + marks);
}//end main

}

Comments

Popular posts from this blog

Code for simple edge detection using C

Why your youtube downloader is not working....