Error code is: Exception in thread \"main\" java.lang.NullPointerException at Co
ID: 440184 • Letter: E
Question
Error code is: Exception in thread "main" java.lang.NullPointerException at CountLetters.main(countLetters.java:25) Code is: //import java.util.Scanner; class CountLetters { /** * This method counts the number of letters in a String */ public void countLetters(String str) { if (str == null) return; int count = 0; for (int i = 0; i < str.length(); i++) { if (Character.isLetter(str.charAt(i))) count++; } System.out.println("The input parameter contained " + count +" letters."); } public static void main(String[] args) { newletters().countLetters("The object of war is not to die for " + "your country but to make the other bastard die for his."); } private static CountLetters newletters() { // TODO Auto-generated method stub return null; } }Explanation / Answer
//import java.util.Scanner; class CountLetters { /** * This method counts the number of letters in a String */ public void CountLetters(String str) { if (str == null) return; int count = 0; for (int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.