标签:main 冒泡排序 code 组复制 程序 byte 自己 package read
package com.jiang.demo01;
public class Demo01 {
public static void main(String[] args) {
String str = "abdfjavaadadjavaadasjavasdfdsfjavadsfdsjavasdf";
int length = str.length();
//获取字符串母串的长度
String java = str.replace("java", "");
//把java用空字符串代替,这样就可以消去java,留下剩下的子串
int length1 = java.length();
//获取子串的长度,用母串的长度减去子串的长度除以java的长度4就是它出现的次数
//这个除数由我们要截的字符串长度决定
System.out.println("java出现了"+(length-length1)/4+"次");
}
}
public class MyTest {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("E:\\断了的弦.mp3");
FileOutputStream fos = new FileOutputStream("D:\\断了的弦.mp3");
byte[] bytes = new byte[1024];
int len = 0;
while ((len=fis.read(bytes))!=-1){
fos.write(bytes,0,len);
}
fos.close();
fis.close();
}
}
public class MyTest {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("E:\\a.txt");
FileOutputStream fos = new FileOutputStream("D:\\a.txt");
int len = 0;
while ((len=fis.read())!=-1){
fos.write(len);//写入文件
}
fos.close();
fis.close()
;
}
}
public class Demo02 {
public static void main(String[] args) {
int [] arr={10,20,30,40,234,4234,23432,566,-121};
for (int j = 0; j < arr.length-1; j++) {
for (int i = 0; i < arr.length-1; i++) {
//遍历数组,如果前面比后面大就往后放
if (arr[i]>arr[i+1]){
int t=arr[i];//使用第三个变量来替换两个值
arr[i]=arr[i+1];
arr[i+1]=t;
}
}
}
System.out.println(Arrays.toString(arr));
}
}
public class Demo02 {
public static void main(String[] args) {
int [] arr={10,20,30,40,234,4234,23432,566,-121};
for (int index = 0; index < arr.length-1; index++) {
for (int i = 1+index; i < arr.length; i++) {
//1+index:自己跟自己不需要比,所以每次遍历往后推一个,就加上外部index循环的值
if (arr[index]>arr[i]){//如果前面的值比后面的值大,就把大的一直往就挪
int t=arr[index];//使用第三个变量来替换两个值
arr[index]=arr[i];
arr[i]=t;
}
}
}
System.out.println(Arrays.toString(arr));
}
}
标签:main 冒泡排序 code 组复制 程序 byte 自己 package read
原文地址:https://www.cnblogs.com/godles/p/11869163.html