vowels and consonant if it is upper or lowercase and special char

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 7105 Views - Last Post: 15 August 2011 - 09:08 PM Rate Topic: -----

#1 jhefandayet06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-August 11

vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 08:42 PM

guys, i am a new to java.. kindly help me to fix my code..

i have to write a java program to print any inputted character if it is lowercase vowel or consonant, then if it is uppercase vowel or consonant, if it is not, print it to special character..

this is the code, please help me.. i'm not yet done with this code

class Input
{
public static void main(String[] args)
{
boolean vowel = false;
System.out.print("Enter an alphabet letter (A through Z : ");
char letter = < a_letter > // Input.class needed to enter a 'char'

switch(letter)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
vowel = true;
break;
default:
vowel = false;
break;
}

if (vowel)
System.out.println(letter + " is a vowel.");
else
System.out.println(letter + " is a consonant");
}
}


my errors are,
Input.java:9: error: illegal start of expression
switch(letter)
^
Input.java:9: error: not a statement
switch(letter)
^
Input.java:9: error: ';' expected
switch(letter)
^
Input.java:11: error: orphaned case
case 'A':
^

kindly help me to finis my code.. thanks a lot in advance.. :helpsmilie: :helpsmilie: :helpsmilie:

Is This A Good Question/Topic? 0
  • +

Replies To: vowels and consonant if it is upper or lowercase and special char

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10773
  • View blog
  • Posts: 40,122
  • Joined: 27-December 08

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 08:56 PM

From what I can see from your code, you need to make this line a legal statement: char letter = < a_letter >. Because the rest of the code is legal. Take a look at the Scanner class for getting user input.
Was This Post Helpful? 1
  • +
  • -

#3 jhefandayet06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-August 11

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:05 PM

THANKS..
char letter = 'A';


but, i still have problem.. i have to identify if it is uppercase or lowercase?. can you tell me some tips on how to do that one? thanks.. =)
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10773
  • View blog
  • Posts: 40,122
  • Joined: 27-December 08

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:06 PM

Check out the Character class. There are a lot of methods there like isUpperCase(), isLowerCase(), etc., that you will find helpful.
Was This Post Helpful? 1
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:11 PM

Character has also toUpperCase() and to LowerCasee()

you can do

letter = Character.toUpperCase(letter);

and the then just switch on A, E, I, O, U
Was This Post Helpful? 0
  • +
  • -

#6 jhefandayet06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-August 11

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:20 PM

on my previous code, i have to use the "user-defined".. i mean, after i run he program, that is the only time i have to input any character.. how can i do that?.
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10773
  • View blog
  • Posts: 40,122
  • Joined: 27-December 08

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:20 PM

Take a look at the Scanner class, as I mentioned above. You will have to import it from the java.util package. :)
Was This Post Helpful? 0
  • +
  • -

#8 jhefandayet06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-August 11

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:22 PM

View Postpbl, on 14 August 2011 - 09:11 PM, said:

Character has also toUpperCase() and to LowerCasee()

you can do

letter = Character.toUpperCase(letter);

and the then just switch on A, E, I, O, U



which part of my code should i do that?.
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:28 PM

import java.util.Scanner;
class Input
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
boolean vowel = false;
System.out.print("Enter an alphabet letter (A through Z : ");
char letter = scan.nextLine().charAt(0);
letter = Character.toUpperCase(letter);

switch(letter)
{
case 'A':
case 'E':


Was This Post Helpful? 0
  • +
  • -

#10 jhefandayet06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-August 11

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:40 PM

View Postpbl, on 14 August 2011 - 09:28 PM, said:

import java.util.Scanner;
class Input
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
boolean vowel = false;
System.out.print("Enter an alphabet letter (A through Z : ");
char letter = scan.nextLine().charAt(0);
letter = Character.toUpperCase(letter);

switch(letter)
{
case 'A':
case 'E':




i still have error.. it says:

cannot find symbol
letter = Character.toUpperCase(letter);
^
symbol: method toUpperCase(char)
location: class Character

thanks..
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10773
  • View blog
  • Posts: 40,122
  • Joined: 27-December 08

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:44 PM

What version of Java are you using? Because that code compiles fine for me.
Was This Post Helpful? 0
  • +
  • -

#12 jhefandayet06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-August 11

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:46 PM

i'm using textpad.. and i downloaded jdk for my compiler..

=(
Was This Post Helpful? 0
  • +
  • -

#13 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10773
  • View blog
  • Posts: 40,122
  • Joined: 27-December 08

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:48 PM

Which version JDK? I'm using Java 6, which is the standard. Documentation for Java 1.4.2 even shows that this syntax is supported. So you must be using a really old version of Java or you are using your own Character class.
Was This Post Helpful? 0
  • +
  • -

#14 jhefandayet06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-August 11

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:52 PM

jdk 1.7.0

can u give me some website where i can download your jdk version?.

thanks..

sorry for many questions..

=(
Was This Post Helpful? 0
  • +
  • -

#15 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10773
  • View blog
  • Posts: 40,122
  • Joined: 27-December 08

Re: vowels and consonant if it is upper or lowercase and special char

Posted 14 August 2011 - 09:54 PM

Java 7 supports this method, as per the documentation. Are you using your own Character class, or a library provided by your instructor that has a Character class? Please post your revised and all relevant code.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2