blank.java
来自「该程序是测试字符串用的」· Java 代码 · 共 58 行
JAVA
58 行
package com.dylan;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Blank {
public static String tool(String str) {
int k1=-1,k2=-1;
int i , j;
for(i= 0 ; i<str.length() ;i++) {
if(str.charAt(i)!= ' '){
break;
}
}
k1 = i;
System.out.println(k1);
for(j= str.length()-1 ; j>=0;j--) {
if(str.charAt(j)!= ' '){
break;
}
}
k2 = j;
System.out.println(k2);
str = str.substring(k1,k2+1);
System.out.println(str.hashCode());
return str;
}
public static void main(String[]args) {
String str1="";
DataInputStream dis = null;
try {
dis = new DataInputStream(new FileInputStream("C:\\test2.txt"));
str1 = dis.readUTF();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
dis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(str1.hashCode());
str1 = tool(str1);
System.out.println(str1.hashCode());
System.out.println(str1);
System.out.println(str1.length());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?