失效链接处理 |
JAVA面试编程题 PDF 下载 下载地址:
提取码:4l9q
相关截图: 主要内容:
1.写一个函数,例如:给你的 a b c 则输出 abc acb bac bca cab cba
package test;
import java.util.ArrayList;
import java.util.List;
public class ListOpreation {
public static void main(String[] args){
String s = "ABCD";
List<String> list = list(s,"");
System.out.println(list.size());
System.out.println(list);
}
public static List<String> list(String base,String buff){
List<String> result = new ArrayList<String>();
if(base.length()<=0){
result.add(buff);
System.out.println(result.toString()+"&");
}
for(int i=0;i<base.length();i++){
List<String> temp = list(new StringBuilder(base).deleteCharAt(i).toString(),buff+base.charAt(i));
result.addAll(temp);
}
for(int i=0;i<base.length();i++){
System.out.println(new StringBuilder(base).deleteCharAt(i).toString()+"=");
System.out.println(base.charAt(i)+"*");
System.out.println(buff+"#");
}
return result;
}
}
执行结果:
2.写一个函数,给你一个字符串 倒序输出来。
package test;
public class ListOperation {
public static void main(String[] args){
String str = "aadsfdfgdfcvsdfsdf";
strOperation(str);
}
private static void strOperation(String str) {
// TODO Auto-generated method stub
System.out.println("str:"+str);
String newStr = "";
for(int i=0;i<str.length();i++){
char c = str.charAt(str.length()-1-i);
newStr = newStr + c;
}
System.out.println("newStr:"+newStr);
}
}
执行结果:
3.不使用中间变量 把两个变量的值互换
package test;
public class ListOperation1 {
public static void main(String[] args){
int a = 20;
int b = 30;
a = a*b;
b = a/b;
a = a/b;
System.out.println("a= "+a+'\n'+"b= "+b);
}
}
4.冒泡排序
package test;
public class ListOperation2 {
public static void main(String[] args){
int[] list = {20,27,15,29,4,14,28};
sort(list);
for(int i=0;i<list.length;i++){
System.out.print(list[i]+" ");
}
System.out.println();
}
public static int[] sort(int[] list){
int temp;
for(int i=0;i<list.length;i++){
for(int j=i+1;j<list.length;j++){
if(list[i]<=list[j]){
temp = list[j];
list[j] = list[i];
list[i] = temp;
}
}
}
return list;
}
}
执行结果:
5.将一个文件复制到另一个文件中。
package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class ListOperation3 {
public static void main(String[] args){
File oldFile = new File("D:\\1.txt");
File newFile = new File("D:\\2.txt");
try {
FileInputStream fis = new FileInputStream(oldFile);
FileOutputStream fos = new FileOutputStream(newFile);
int read = 0;
while((read=fis.read())!=-1){
fos.write(read);
fos.flush();
}
fos.close();
fis.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
执行结果:
|