Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Problem Finding Character Types

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is to create a Java program that will ask the user to input any type of String values via command line. The output should contain the args[i] value, the length of the inputted String, the actual String and the type of character of the last character of the inputted String. The types of characters are as follows: vowels, consonants, numbers and symbols. The only time you can consider a certain character as a symbol is when it is not a vowel, nor a consonant nor a number. Here’s a sample IO:

java ICS112_1ITB_Exercise5_Beltran_25 productiveWork 7654321 javajava $$$ <ENTER>

Output:

args[0] = productiveWork = 14 = consonant
args[1] = 7654321 = 7 = number
args[2] = javajava = 8 = vowel
args[3] = $$$ = 3 = symbol



IDK WTH is wrong with my codes?
 
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well this looks like an assignment but let's see what we can do to help you figure this out and learn from it.
Is your code building and are you using an ide to debug it or are you using a text editor?
What is it currently doing?

EDIT: I'll give you your first hint, check your while statement syntax. After that you'll start seeing something....
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My first question would be: You're starting out with case statements for the lowercase vowels, but then you abandon that approach in the default section for something rather unwieldy with lots of if statements; why are you not using case statements for ALL possible cases?
 
Marc Cracco
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also you should take a look at the javadoc: java.util.Scanner
 
Ranch Hand
Posts: 65
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HINT: the time spent on coding case statements on this problem might be equal on studying basic regex.
 
Marshal
Posts: 74651
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am not convinced the last hint is going to be very helpful.
You appear to be confusing the command‑line arguments with text input at runtime. Which are you going to use?
You have also goo far too long a method. You should divide that into getting input, finding the last character, and determining its type.
You do realise that a char is not a letter? It is a number, and you can therefore find ranges of numbers, do arithmetic with them, etc.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic