Results 1 to 2 of 2
  1. #1
    lenny is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default 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.

    Java 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

  2. #2
    mirage_87 is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default

    why are using "=" in a condition statement............u must be using "=="....
    i guess this might solve yr problem.

Similar Threads

  1. How can i insert a char into a string
    By Jamie in forum New To Java
    Replies: 8
    Last Post: 02-17-2011, 09:59 PM
  2. Casting an int value into a char
    By kurtulas in forum New To Java
    Replies: 2
    Last Post: 02-16-2008, 09:03 PM
  3. Cannot convert from char to String error
    By sondratheloser in forum New To Java
    Replies: 1
    Last Post: 12-13-2007, 10:28 PM
  4. need help print char and digital
    By lowpro in forum New To Java
    Replies: 4
    Last Post: 12-04-2007, 08:20 AM
  5. Char to String in java
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 02:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •