학교과제인데
문장입력하면 총 글자개수, 각 모음별 개수 보여주는 건데...
자기가 원하는 만큼 계속해서 입력할 수 있고.
다했는데.. 문제가 그만하고 싶을때 close버튼 누르면 자꾸 java. lang.NullPointerException이라는 오류가 발생해..
in extra credit lab4, when i compile and run the program, it works. input message is showing as much as I want. I used infinite loop for this. However, the problem is close button. when i press close button, it is saying "java.lang.NullPointerException". can you help which is the problem?
BlueJ highlighted the part that "for (i=0; i<inputString.length();i++)".
here is my code
--------------------------------------------------------------------------------------------------------------------------
import javax.swing.JOptionPane;
public class Vowel2
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null, "This program asks the user for a sentence,\n"
+"searches the sentence for all vowels,\n"+"and displays the number of times each\n"
+"vowel appears in the sentence.","",JOptionPane.INFORMATION_MESSAGE);
String inputString;
int aCount=0, iCount=0, uCount=0, eCount=0, oCount = 0;
int i;
while(true)
{
inputString=JOptionPane.showInputDialog("Enter the sentence to search");
for (i=0; i<inputString.length();i++)
{
if(inputString.charAt(i)=='A'||inputString.charAt(i)=='a')
{
aCount++;
}
if(inputString.charAt(i)=='I'||inputString.charAt(i)=='i')
{
iCount++;
}
if(inputString.charAt(i)=='U'||inputString.charAt(i)=='u')
{
uCount++;
}
if(inputString.charAt(i)=='E'||inputString.charAt(i)=='e')
{
eCount++;
}
if(inputString.charAt(i)=='O'||inputString.charAt(i)=='o')
{
oCount++;
}
}
String outputMessage= inputString+"\n\n"+"has "+inputString.length()+" characters."+"\n\nThere are\n"+aCount+" a's,\n"+eCount+" e's,\n"+iCount+" i's,\n"+oCount+
" o's, and\n"+uCount+" u's.";
JOptionPane.showMessageDialog(null,outputMessage,"", JOptionPane.INFORMATION_MESSAGE);
}
}
}
---------------------------------------------------------------------------------------------------------------------------
어디가 문제인가여??
댓글 0