how to make program that keeps score and loops till XXX is inputed
hi can some1 pls help me out im trying to make a program that loops till you type in xxx. i got that part done but the main goal of the program is that you need to type in a word and then the following word's first letter should start with the previous word's last letter for e.g. input:hello input:over input:rare input:xxx
output:score:3
if the word doesnt start with the previous word last letter it is counted as incorrect and if it starts with the last letter it is correct
later on the score = correct - incorect to get score here is my code pls help me out im strugling bad with this program
here is code Code:
String bgnword = JOptionPane.showInputDialog("Enter a begin word: ");
int score;
int len = bgnword.length();
score = 0;
String word;
int corwrd = 0;
int incwrd = 0;
String prevword = null;
while(!"XXX".equals(word = JOptionPane.showInputDialog("Enter a word or XXX to quit.")))
{
char bgn = bgnword.charAt(len - 1);
prevword = word;
int len2 = word.length();
char ch1 = word.charAt(0);
char ch2 = prevword.charAt(len2 - 1);
if (prevword != null)
{
if(ch1 == ch2)
{
corwrd++;
}
else
{
incwrd--;
}
score = corwrd - incwrd;
}
}
System.out.println("Score: " + score);
Re: how to make program that keeps score and loops till XXX is inputed
can any1 pls help me on this 1
Re: how to make program that keeps score and loops till XXX is inputed
Please execute the program and Post the program's output here.
Add comments to the output saying what is wrong with it and show what the output should be.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.