?编写博客目的:本系列博客均根据B站黑马程序员系列视频学习和编写目的在于记录自己的学习点滴,方便后续回忆和查找相关知识点,不足之处恳请各位有缘的朋友指正。
?第一题:false
第二题:true?
package StringJoinerDemo1;
import java.util.Scanner;
public class StringJoinerDemo2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str;
while (true){
System.out.println("请输入一个字符串");
str = sc.next();
boolean flag = checkStr(str);
if(flag){
break;
}else {
System.out.println("当前字符串不符合规则,请重新输入");
continue;
}
}
String s = "";
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
int number = c - 48;
s = s + changeLuoMa(number);
}
System.out.println(s);
}
public static String changeLuoMa(int number){
String[] arr = {"","Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ","Ⅷ","Ⅸ"};
return arr[number];
}
public static boolean checkStr(String str) {
if (str.length() > 9) {
return false;
}
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c < '0' || c > '9') {
return false;
}
}
return true;
}
}
package test;
public class test1 {
public static void main(String[] args) {
// 定义两个字符串
String strA = "abcde";
String strB = "cdeab";
boolean result = check(strA,strB);
System.out.println(result);
}
public static boolean check(String strA,String strB){
for (int i = 0; i < strA.length(); i++) {
strA = rotate(strA);
if(strA.equals(strB)){
return true;
}
}
return false;
}
public static String rotate(String str){
char first = str.charAt(0);
String end = str.substring(1);
return end + first;
}
}