/*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);
}
}
}
aladar04
0
Light Poster
Recommended Answers
Jump to PostUse 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;
All 3 Replies
aladar04
0
Light Poster
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
aladar04
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.