java - Setting a parameter for returned string values -
i trying create game user enters phrase, phrase can in lower case letters (if catch drift). program prompt user do-while loop. if user enters (1234567890, or !@#$%^&* or asdfgh, loop should re-prompt user enter lower case letters. extremely new java, code going shitty. here is:
import java.util.scanner; public class program05 { public static void main(string[] args) { scanner scanner01 = new scanner(system.in); string inputphrase; char inputchar; { system.out.print("enter common phrase begin!: "); inputphrase = scanner01.nextline(); } while (!inputphrase.equals(character.digit(0,9))); } }
use string.matches()
appropriate regex test if it's lowercase letters:
inputphrase.matches("[a-z ]+") // consists of characters a-z , spaces
so loop like:
do { system.out.print("enter common phrase begin!: "); inputphrase = scanner01.nextline(); } while (!inputphrase.matches("[a-z ]+"));
Comments
Post a Comment