4 Replies - 4125 Views - Last Post: 03 April 2011 - 11:38 AM Rate Topic: -----

#1 javaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-April 11

Printing a letter using asterisks!

Posted 02 April 2011 - 06:55 PM

I'm new to the "System.out.printf()" but was asked to print the first letter of whatever word the user enters, using asterisks.

I'm not looking for solutions, just help about how I can use "System.out.printf()" to do so.

The only way that I could think of is creating 'if statements' for each and every letter.

Is there an easier way of doing so without having to specify each and every single one(letter)?

Is there a method or something in JAVA that I'm not aware of that can help?!

Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: Printing a letter using asterisks!

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Printing a letter using asterisks!

Posted 02 April 2011 - 07:08 PM

How are you storing user input? char[] or String?


Misread. You need to print out a letter IN asterisks?


You'll have to do a cascading if/else or a switch, there is no consistent pattern between letters in the alphabet.
Was This Post Helpful? 0
  • +
  • -

#3 javaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-April 11

Re: Printing a letter using asterisks!

Posted 02 April 2011 - 07:19 PM

Yes, I have to print IN asterisks.

Like if I entered the word "Fail", my program should be able to print the output as such:

*****
*
***
*
*

That's what I thought, but I'd have to do all 27 letters wouldn't I?!
I was hoping for a perhaps easier way of doing so.
I am not really familiar with the switch.
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Printing a letter using asterisks!

Posted 02 April 2011 - 07:35 PM

Well, all 26 letters, unless there's been a change no one told me about ;)


Switch would look something along the lines of:

String userInputFake = "Bob";
switch(userInputFake.charAt(0)){
     case 'A':
          //draw
          break;
     case 'B':
         //hey bob!
         break;
///etc...
}


Was This Post Helpful? 0
  • +
  • -

#5 javaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-April 11

Re: Printing a letter using asterisks!

Posted 03 April 2011 - 11:38 AM

Yes, 26.
You'll have to excuse me, it was late and I wasn't completely focused.
Thank you for all your help, I will need more time to think it over and figure it out and I'll let you know what I come up with if you'd like.

Thank you again! :)

This post has been edited by javaf: 03 April 2011 - 11:42 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1