一 字符串中,连续重复的元素去除
import java.util.Scanner;
public class Test01 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String str=scanner.next();
String myArray[]=str.split(",");
String newArray="";
for (int i = 0; i < myArray.length-1; i++) {
if(myArray[i]!=myArray[i+1]){
newArray=newArray+myArray[i];
}
}
System.out.print(newArray);
}
}
二 字符串中,把数组倒序输出
public class Test02 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String str=scanner.next();
for (int i = 0; i < str.length(); i++) {
System.out.print(str.charAt(str.length()-i-1)+"");
}
}
}
三 给数组排序
public class Test04 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int []arr=new int[25];
for (int i = 0; i < ; i++) {
arr[i]= scanner.nextInt();
}
Arrays.sort(arr);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
四 输出99乘法表
public class Test04 {
public static void main(String[] args) {
for (int i = 1; i <=9 ; i++) {
for(int j=1;j<=i;j++){
System.out.print(i+"*"+j+"="+i*j);
}
System.out.print();
}
}
}
五 键盘上输入一些字符,逐个把它们写到一个磁盘文件上,直到输入一个#为止
public class Test04 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
File file=new file("test");
FileWriter filewriter=new FileWriter("file");
BufferdWriter bw=new BufferdWriter("filewriter");
String str;
while( true){
System.out.println("请输入信息");
str= sc. nextLine;
if("#". equals"str"){
break;
}
bw. write(str)
}
bw. close();
fw.close(
}
}