0
/*manimbo_mp5*/
import java.io.*;
	public class manimbo_mp5{
		public static void main (String[]args) throws IOException{
			BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
			Integer x=8,y=1,heads=0,tails=0;
			String ht="";
			while (x>0){
				System.out.print ("Enter toss #" + y + " result: ");
				ht=br.readLine();
				if (ht=="h"){
					heads++;
				}
				else if (ht=="t"){
					tails++;
				}
				x--;
				y++;
				System.out.println ("Tails: " + tails);
				System.out.println ("Heads: " + heads);
				System.out.println ("ht is " + ht);
			}
		}
	}
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by aladar04
0

Use the equals method to compare Strings:

if ( ht.equals("h") ) {

}

Also you don't need to declare your integers Integer. Simple int will suffice:

int x=8,y=1,heads=0,tails=0;
This question has already been answered. 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.