题目再现
//Lab4-1反转字符串
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
str = new StringBuffer(str).reverse().toString();
System.out.println(str);
}
题目2 文本中查找字符串
题目再现:
//Lab4-2文本中查找字符串
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String pattern = sc.next();
for(int i =0;i
题目3–替换字符串
题目再现
完整代码
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String pattern = sc.next();
int cnt = 0;
String des = sc.next();
for(int i =0;i
实验效果
实验4-十六进制互转
public static void main(String[] args) {
while(true){
System.out.println("1、for hex to decn2、for dec to hex");
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(scanner.nextLine());
if (n == 2){
System.out.println("Enter a dec string:");
int d = scanner.nextInt();
String s = Integer.toHexString(d).toUpperCase();
System.out.println("Decimal value for hex string:"+s);
}else {
System.out.println("Enter a hex string:");
String h = scanner.nextLine();
int i = Integer.parseInt(h, 16);
System.out.println("hex value value to dec string:"+i);
}
}
}



