Homework02
package com.hspedu.Exercise0;
import java.util.Scanner;
/**
* @author Lei jinquan ~
* @version 1.0
*/
public class Homework02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入用户名");
String user = scanner.next();
System.out.println("请输入密码");
String password = scanner.next();
System.out.println("请输入邮箱");
String email = scanner.next();
try {
check(user, password, email);
System.out.println("恭喜你注册成功");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static void check(String user, String password, String email) {
if (!(user.length() <= 4 && user.length() >= 2)) { //第一关
throw new RuntimeException("用户名的字符溢出!");
}
if (!(password.length() == 6 && isDigital(password))) {//第二关
throw new RuntimeException("您的密码长度为6,且为数字!");
}
// if (!(password.length() == 6)) {
// throw new RuntimeException("密码不符合长度为6");
// }
// try {
// Integer.parseInt(password);
// } catch (NumberFormatException e) {
// System.out.println("注册失败输入的密码不是纯数字" + e.getMessage());
// return;
// }
int temp = email.indexOf("@");
int temp1 = email.indexOf(".");
if (!(temp > 0 && temp1 > temp)) {
throw new RuntimeException("邮箱格式未包含@.且@在.后");
}
}
public static boolean isDigital(String str) {
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] < '0' || chars[i] > '9') {//Asics码值比较
return false;
}
}
return true;
}
}
Homework03 运用sqlit和format进行重新排序
package com.hspedu.Exercise0;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import java.util.jar.JarEntry;
/**
* @author Lei jinquan ~
* @version 1.0
*/
public class Homework3 {
public static void main(String[] args) {
changename("Han shun Ping");
}
public static void changename(String str) {
if (str == null) {
System.out.println("输入值为空");
return;
}
String[] names = str.split(" ");//分割成数组
if (names.length != 3) {
System.out.println("输入的字符串格式不对");
return;
}
String format = String.format("%s,%s .%c", names[2], names[0], names[1].toUpperCase().charAt(0));
//toUpperCase().charAt(0)首字母大写
System.out.println(format);
}
}
判断字母大小写和其他
package com.hspedu.Exercise0;
import java.util.zip.CheckedOutputStream;
/**
* @author Lei jinquan ~
* @version 1.0
*/
public class Homework04 {
public static void main(String[] args) {
String str = "Lei Jin Quan";
big(str);
}
// public static void big(String str) {
// if (str == null){
// System.out.println("输入值为空");
// return;
// }
// int count = 0;
// char[] chars = str.toCharArray();
// for (int i = 0; i <chars.length ; i++) {
// if ( chars[i] >= 'A' && chars[i] <= 'Z'){
// count ++ ;
// }
// }
// System.out.println("大写字母有" + count + "个");
// }
//
public static void big(String str) {
int Strlen = str.length();
int SpaceNum = 0;
int lowerCount = 0;
int bigCount = 0;
int otherCount = 0;
for (int i = 0; i <Strlen ; i++) {
if (str.charAt(i) == ' '){
SpaceNum++;
}else if (str.charAt(i)>= 'a'&& str.charAt(i)<='z'){
lowerCount++;
}else if (str.charAt(i)>= 'A'&& str.charAt(i)<='Z'){
bigCount++;
}else{
otherCount++;
}
}
System.out.println(" 空格数量为 " + SpaceNum + " 小写字母数量为 " + lowerCount + " 大写字母数量为 " + bigCount
+ " 其他字母数量为 "+ otherCount);
}
}