公司的專案做完在交接給客戶,沒事就寫了幾個Java小練習了,自己想的做的所以技術渣,勿噴,學習學習
工具/原料
eclipse
方法/步驟
開啟txt1,把txt1的內容複製到txt2裡面去
猴子吃桃問題
迴文數判斷
逆序輸出 輸入一個字串,將其逆轉並輸出。
2個數交換
拉丁豬文字遊戲——這是一個英語語言遊戲。
基本規則是將一個英語單詞的第一個子音音素的字母移動到詞尾並且加上字尾-ay
(譬如“banana”會變成“anana-bay”)。可以在維基百科上了解更多內容。
a e i o u是母音,y是半母音,其他子音
判斷是否是閏年
每隔一段時間執行一個任務
100-999之間的水仙花數
求規則數列的前10項的和
用*做的一個正三角形
算出有多少隻兔子
開啟檔案,搜尋裡面的文字
package com.java.test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 開啟檔案,搜尋裡面的文字
* @author
* @version 1.0.0
* @date 2016年8月9日,上午9:30:56
* @see
*/
public class WenjianChuli {
public static void main(String[] args) {
BufferedWriter fout=null;
FileWriter fw = null;
try{
BufferedReader bf= new BufferedReader(new FileReader("e:/Hello.java"));
File file = new File("e:/Hello1.java");
fw = new FileWriter(file);
fout=new BufferedWriter(fw);
String line=null;
String int1="int";
String newstr="*1";
String int2="=";
String newstr2="*2";
String int3="\".+\"";
String newstr3="*3";
while((line=bf.readLine())!=null){
Pattern pattern = Pattern.compile(int1);
Matcher m=pattern.matcher(line);
if(m.find()){
line=line.replaceAll(int1, newstr);
}
Pattern pattern1 = Pattern.compile(int2);
Matcher m1=pattern1.matcher(line);
if(m1.find()){
line=line.replaceAll(int2, newstr2);
}
Pattern pattern2 = Pattern.compile(int3);
Matcher m2=pattern2.matcher(line);
if(m2.find()){
line=line.replaceAll(int3, newstr3);
}
System.out.println(line);
fout.write(line);
fout.newLine();
}
bf.close();
fout.flush();
fout.close();
}catch(IOException ioe){
System.out.println("File Write Error!"+ioe);
}
}
}
輸入一個五位數,每位數的數字相加
統計母音字母——輸入一個字串,統計處其中母音字母的數量。更復雜點的話統計出每個母音字母的數量。
package com.java.test;
import java.util.Scanner;
/**
* 統計母音字母——輸入一個字串,統計處其中母音字母的數量。更復雜點的話統計出每個母音字母的數量。
* @author
* @version 1.0.0
* @date 2016年8月5日,下午3:10:29
* @see
*/
public class Yuanyin {
public static void main(String[] args) {
System.out.println("請輸入字串");
Scanner sc=new Scanner(System.in);
String str1=sc.next();
int a=0,e=0,u=0,i=0,o=0;
for(int i1=0;i1
char c=str1.charAt(i1);
if(c=='a'){
a++;
}
if(c=='e'){
e++;
}
if(c=='u'){
u++;
}
if(c=='i'){
i++;
}
if(c=='o'){
o++;
}else{
}
}
System.out.println("a:"+a+" e:"+e+" o:"+o+" i:"+i+" u:"+u);
}
}
字串替換問題
注意事項
暫時就這麼多了,還有幾個就算了