View Single Post
  #1 (permalink)  
Old 07-24-2007, 03:47 AM
lenny lenny is offline
Member
 
Join Date: Jul 2007
Posts: 40
lenny is on a distinguished road
Help with, String, Char
Hi, i am writing a program for my class and is what it has to do is take a string input from the user and then it has to output the length of the string and how many vowels are in the string.
I have tried everything i can think of, but i need help. I keep getting unexpected type error on all of my if statements I think it is because of what I am trying to compare, but I just don't know any other way to do it. All i need is a little help or point me in the right direction.

Code:
import java.util.*; public class Assignment6 { public static void main(String[] args) { String a; int i, j, x; j = 0; x = 0; Scanner scannerKeyboard = new Scanner(System.in); System.out.println("Please enter a sentance: "); a = scannerKeyboard.nextLine(); a.toUpperCase(); for (i = 0; i <= 100; i++){ if (a.charAt(i) = (char)65) j++; else if (a.charAt(i) = (char)69) j++; else if (a.charAt(i) = (char)73) j++; else if (a.charAt(i) = (char)79) j++; else if (a.charAt(i) = (char)85) j++; else x++; } System.out.println("The length of the string entered is " + a.length()); System.out.println("The string you entered has this amount of vowels: " + j); System.out.println("It also has this amount of whitespace and consanants: " + x); } }
Thanks
Reply With Quote
Sponsored Links