Java Beginners

Moderators: zibadian
Number of threads: 1285
Number of posts: 2739

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
String Manipulation. HELP! Posted by Nemus on 21 Sept 2011 at 11:21 AM
Hi, my name is Mat and I'm new to the Java language. I recently started a programming class that focuses on Java. I'm stuck on one of the my assignments. The assignment seems fairly simple but I seem to be stuck. Here is the assignment:
-----
"Write a Java program that reads a patient’s first name, last name and age from keyboard and then creates and displays a unique patient identifier formed by the initials of each name and the reversed age value.
For example, if the patient’s first name is John, his last name is Smith and his age is 29 years old, your
program must display the following identifier:
JS92
Note: Assume the patient’s age ranges between 10 and 99."
---

Here's what I have so far:



public static void main(String[] args) {
String firstName, lastName;
int age;

System.out.println("Please enter your first name.");
Scanner keyboard = new Scanner (System.in);
firstName = keyboard.nextLine ();

System.out.println("Please enter your last name.");
lastName = keyboard.nextLine ();

System.out.println("Please enter your age.");
age = keyboard.nextInt();

String sentence = firstName + lastName + age;
int position = sentence. indexOf (firstName);
System.out.println (sentence);


{


If someone with experience could maybe offer some advice in the right direction, it would be greatly appreciated. Thank you!

-Nemus

Report
Re: String Manipulation. HELP! Posted by SoEnLion on 23 Sept 2011 at 3:13 AM
try this :
sentence = firstName.substring(0,1) + lastName.substring(0,1) + age.toString();



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.