I AM WORKING ON THIS CODE, THERE ARE SOME ERROR PLS HELP ME FIX THESE. THE PROGRAM SUPPOSE TO DO. 1. Ask the user to type in a sentence, using a JOptionPane.showInputDialog(). 2. The program will scan the string and count how many upper-case letters appear, and how many lower-case letters appear. 3. Tell the user how many upper/lower case letters there were using a JOptionPane.showMessageDialog() 4. Repeat this process until the user types the word "Stop".
MY PROGRAM IS VERY MESSED UP, IF YOU WANT REWRITE THE PROGRAM PLS DO SO, I REALLY APERICATE THE HELP, THANKS AFTER FIXING THE CODE PLS PUT THE NOTES IN THE PROGRAM SO I CAN UNDERSTAND EVERYTHING
here's the program
import javax.swing.*;
public class project { public static void main (String [] args) { String line = JOptionPane.showinputDialog ( "Please enter a sentence.") line = input.nextLine();
While (! line.equals ("STOP") ) System.out.println("Your string contains " + lowercaseLCVowelCount(line) + " Number of lower case letters:"); System.out.println("Your string contains " + uppercaseLCVowelCount(line) + " Number of Upper case letters"); System.exit(0); }
public static int lowercasepro(String text) { int count = 0; for ( int i = 0; i < text.length(); i++ ) { char x = text.charAt(i); if ( x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' ) count++; }
public static int uppercasepro(String text) { int count = 0; for ( int i = 0; i < text.length(); i++ ) { char x = text.charAt(i); if ( x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U' ) count++; return count; } }
public class UIProject { public static void main (String [] args) { String line = JOptionPane.showInputDialog( "Please enter a sentence."); //line = input.nextLine(); while (! line.equals ("STOP") ) { System.out.println("Your string contains " + lowercasepro(line) + " Number of lower case letters:"); System.out.println("Your string contains " + uppercasepro(line) + " Number of Upper case letters"); System.exit(0); } }
public static int lowercasepro(String text) { int count = 0; for ( int i = 0; i < text.length(); i++ ) { char x = text.charAt(i); if ( x >= 'a' && x <= 'z') count++; } return count; }
public static int uppercasepro(String text) { int count = 0; for ( int i = 0; i < text.length(); i++ ) { char x = text.charAt(i); if ( x >= 'A' && x <= 'Z') count++; //return count; } return count; } }