Checking string formats in Java? -
having problems doing class i'm taking, since missed class or two. (i know it's looked down on 'do someone's homework,' i'm not looking that.)
the assignment follows:
write program following:
- prompt input of someone's first, middle, , last name single string (using combination of upper , lowercase letters).
- check make sure name entered in correct format (3 names separated spaces). if input not correct, continue request input again until format correct.
- capitalize first letters of each part of name, , print out revised name.
- print out initials name.
- print out name in format of: lastname, firstname, mi.
the major problem i'm having second part of assignment; got first part, , i'm sure can manage through rest, after second set up.
import java.util.*; public class teststrings { public static void main(string[] args) { scanner key = new scanner(system.in); string name; system.out.print("enter name 'first middle last': "); name = key.nextline(); } }
from i've gathered, need use string.split? i'm not sure how go this, though, since need check make sure there 3 spaces, aren't right next each other or something, such "john(three spaces)doe". assume it's going kind of loop check through input name.
the catch 22, can't use arrays, or stringtokenizer. must use substring method.
any appreciated. thanks. :d
to point in right direction find first name(since cant use arrays):
string firstname = input.substring(0, input.indexof(" "));
this substring start first space. if research indexof , substring methods should able go there.
Comments
Post a Comment