Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This code has TEN errors that you must find and fix import java.util.Scanner; pu

ID: 3574713 • Letter: T

Question

This code has TEN errors that you must find and fix

import java.util.Scanner;

public class countingVowelsAndConsonnants {
  
public static void main (String [] args ) {
  
Scanner in = new Scanner(System.in);
System.out.print("Enter a sentence, lowercase only: ");
String sentence = in.nextLine();
int [] thing;
thing = letterCoutner(sentence);
System.out.println("There are: " + thing[1] + "vowels,");
System.out.println(+ thing [2] + "consonnants and" + thing[3] );
}
static public int [] letterCounter([] String sentences){;

String vowels = "aeiouy";
int counter = 0;
int space = 0;
int [] result = {0,0,0};
  
for (int j=0; j<= sentence.lenth(); j++) {
  
if (sentence.charAt(j)==' ' )
{ j =j+1;
space++;
}
  
for (int k=0 ; k < vowels.length() ; k++) {
if (sentence.charAt(j)==vowels.charAt(k)) {
}
}
}
result[0]= void;
result[1]= sentence.length()- counter - space;
result[2]= space;
return result[3];
return;
}
}
  

Explanation / Answer

Hi

I have fixed all issue. It is working fine as expected and highlighted the code changes below.

countingVowelsAndConsonnants.java


import java.util.Scanner;
public class countingVowelsAndConsonnants {
  
public static void main (String [] args ) {
  
Scanner in = new Scanner(System.in);
System.out.print("Enter a sentence, lowercase only: ");
String sentence = in.nextLine();
int [] thing;
thing = letterCounter(sentence);
System.out.println("There are: " + thing[0] + " vowels,");
System.out.println( thing [1] + " consonnants and " + thing[2] );

}
static public int [] letterCounter(String sentence){;

String vowels = "aeiouy";
int counter = 0;
int space = 0;
int [] result = {0,0,0};
  
for (int j=0; j< sentence.length(); j++) {
  
if (sentence.charAt(j)==' ' )
{ j =j+1;
space++;
}
  
for (int k=0 ; k < vowels.length() ; k++) {
if (sentence.charAt(j)==vowels.charAt(k)) {
   counter++;
}
}
}
result[0]= counter;
result[1]= sentence.length()- counter - space;
result[2]= space;
//return result[3];
return result;
}
}
  

Output:

Enter a sentence, lowercase only: suresh murapaka
There are: 6 vowels,
8 consonnants and 1