标签:imp next end while str stat author with static
import java.util.Scanner;
/**
*
*/
/**
* Homework14
*
* @Description:用户输入一个字符串,如果以a结尾,则认为是合法字符串,否则为非法字符串,提示用户重新输入。 Test04
*
* @author
*
* email: 1816274408@qq.com 2017年4月21日上午12:27:02
*
*/
public class Test04 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("请输入一个字符串:\t");
String str = scan.next();
if (str.endsWith("a")) {
System.out.println("字符合法!");
break;
} else {
System.out.println("不合法字符,请重新输入:");
}
}
}
}
用户输入一个字符串,如果以a结尾,则认为是合法字符串,否则为非法字符串,提示用户重新输入
标签:imp next end while str stat author with static
原文地址:http://www.cnblogs.com/Jack1816274408/p/6746420.html