文件out.txt中,有如下内容:239、567、345
540/137/879
247//839//693
658/369/147
247//十:389//个:369
4679---4679---4679
3469*0479*3689
345679 、 013568 、 52980371。。多条数据
要求:
编写程序,从out.txt中读取内容,经过处理后,显示
效果(每行一条数据)如下:0145678、0123489、0126789
1236789、0245689、0123456
0135689、0124567、0124578
0123479、0124578、0235689
0135689、0124567、0124578
012358、012358、012358
012578、123568、012457
0128、2479、46注:相当于将每条数据中,每部分数字换成没有出现的数字(0~9)
如: 345679 、 013568 、 52980371 这条数据
经过处理后,变成:
0128、2479、46 这条数据。
540/137/879
247//839//693
658/369/147
247//十:389//个:369
4679---4679---4679
3469*0479*3689
345679 、 013568 、 52980371。。多条数据
要求:
编写程序,从out.txt中读取内容,经过处理后,显示
效果(每行一条数据)如下:0145678、0123489、0126789
1236789、0245689、0123456
0135689、0124567、0124578
0123479、0124578、0235689
0135689、0124567、0124578
012358、012358、012358
012578、123568、012457
0128、2479、46注:相当于将每条数据中,每部分数字换成没有出现的数字(0~9)
如: 345679 、 013568 、 52980371 这条数据
经过处理后,变成:
0128、2479、46 这条数据。
public class ChangeNumbers {
static List<String> strList = new ArrayList<String>();
public static void main(String[] args) {
File f = new File("out.txt");
FileReader fr;
try {
fr = new FileReader(f);
int readChar = -1;
String s = "";
while((readChar = fr.read()) != -1){
if(isNumber((char)readChar)){
s += String.valueOf((char)readChar);
}else{
if(s != ""){
strList.add(s);
s = "";
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
String outLine = "";
for(int i = 1;i <= strList.size();i++){
outLine += (getNumbers(strList.get(i-1)))+"、";
if(i%3 == 0){
if(outLine.endsWith("、")){
outLine = outLine.substring(0,outLine.length()-1);
}
System.out.println(outLine);
outLine = "";
}
}
}
static boolean isNumber(char c){
if(c >= '0' && c <= '9'){
return true;
}
return false;
}
static String getNumbers(String s){
List<String> numList = new ArrayList<String>();
for(int i = 0;i<10;i++){
numList.add(String.valueOf(i));
}
for(int i = 0;i<s.length();i++){
char c = s.charAt(i);
for(int j = 0;j<numList.size();j++){
if(numList.get(j).equals(String.valueOf(c))){
numList.remove(j);
}
}
}
String retval = "";
for(String str:numList){
retval += str;
}
return retval;
}
}输出:0145678、0123489、0126789
1236789、0245689、0123456
0135689、0124567、0124578
0123479、0124578、0235689
0135689、0124567、0124578
012358、012358、012358
012578、123568、012457
0128、2479、46
不过数字之间只有空格时。如何正确输出。
如:
345 679 、enlish十:有 013 568 、 529 80371
输出:
0128、2479、46
540/137/879
247//839//693
658/369/147
247//十:389//个:369
4679---4679---4679
3469*0479*3689
345679 、 013568 、 52980371
345 679 、enlish十:有 013 568 、 529 80371ChangeNumbersWithSpace.javaimport java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;public class ChangeNumbersWithSpace {
static List<String> strList = new ArrayList<String>();
public static void main(String[] args) {
File f = new File("out.txt");
FileReader fr = null;
try {
fr = new FileReader(f);
int readChar = -1;
String s = "";
while((readChar = fr.read()) != -1){
if(isNumberOrSpace((char)readChar)){
s += String.valueOf((char)readChar);
}else{
if(s != ""){
strList.add(s.replaceAll(" ", ""));
s = "";
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
fr.close();
fr = null;
} catch (IOException e) {
e.printStackTrace();
}
}
String outLine = "";
for(int i = 1;i <= strList.size();i++){
outLine += (getNumbers(strList.get(i-1)))+"、";
if(i%3 == 0){
if(outLine.endsWith("、")){
outLine = outLine.substring(0,outLine.length()-1);
}
System.out.println(outLine);
outLine = "";
}
}
}
static boolean isNumberOrSpace(char c){
if(c >= '0' && c <= '9' || c ==' '){
return true;
}
return false;
}
static String getNumbers(String s){
List<String> numList = new ArrayList<String>();
for(int i = 0;i<10;i++){
numList.add(String.valueOf(i));
}
for(int i = 0;i<s.length();i++){
char c = s.charAt(i);
for(int j = 0;j<numList.size();j++){
if(numList.get(j).equals(String.valueOf(c))){
numList.remove(j);
}
}
}
String retval = "";
for(String str:numList){
retval += str;
}
return retval;
}
}输出:0145678、0123489、0126789
1236789、0245689、0123456
0135689、0124567、0124578
0123479、0124578、0235689
0135689、0124567、0124578
012358、012358、012358
012578、123568、012457
0128、2479、46
0128、2479、46
如:
027一027一027
12/56/039
246--2379--079
39/48/17
179/679/479
019/268/1249
017/138/18
246/059/579
0567、035、378
029/593/3458
786/058/925
157/135/579
089、027、179
026//56//58
028/39/24
135/357/248
719/60/850
135/15/389
256 十位:19 个位:034
7--1238--178
157//015//847
139/678/1357
147/147/369
046/468/068
237/124/027
369/147/258
3579/578/135
057/378/358
257/789/139
376/45/14 三十条数据,统计结果时:显示29条记录。
1345689、1345689、1345689
03456789、01234789、1245678
0135789、014568、1234568
01245678、01235679、02345689
0234568、0123458、0123568
2345678、0134579、035678
2345689、0245679、02345679
0135789、1234678、0123468
123489、1246789、0124569
1345678、0124678、012679
0123459、1234679、0134678
0234689、0246789、0123468
1234567、1345689、0234568
1345789、01234789、01234679
1345679、01245678、01356789
0246789、0124689、0135679
0234568、12345789、1234679
0246789、02346789、0124567
0134789、02345678、1256789
012345689、045679、0234569
0234689、2346789、0123569
0245678、0123459、024689
0235689、0235689、0124578
1235789、0123579、1234579
0145689、0356789、1345689
0124578、0235689、0134679
012468、0123469、0246789
1234689、0124569、0124679
0134689、0123456、0245678程序不完善。
03456789、01234789、1245678
0135789、014568、1234568
01245678、01235679、02345689
0234568、0123458、0123568
2345678、0134579、035678
2345689、0245679、02345679
0135789、1234678、0123468
123489、1246789、0124569
1345678、0124678、012679
0123459、1234679、0134678
0234689、0246789、0123468
1234567、1345689、0234568
1345789、01234789、01234679
1345679、01245678、01356789
0246789、0124689、0135679
0234568、12345789、1234679
0246789、02346789、0124567
0134789、02345678、1256789
012345689、045679、0234569
0234689、2346789、0123569
0245678、0123459、024689
0235689、0235689、0124578
1235789、0123579、1234579
0145689、0356789、1345689
0124578、0235689、0134679
012468、0123469、0246789
1234689、0124569、0124679
0134689、0123456、0245678
0124589、01236789、02356789
ChangeNumbersNew.javaimport java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;public class ChangeNumbersNew {
static List<String> strList = new ArrayList<String>();
public static void main(String[] args) {
File f = new File("out.txt");
FileReader fr = null;
BufferedReader br = null;
try {
fr = new FileReader(f);
br = new BufferedReader(fr);
String lineStr = "";
String s = "";
while((lineStr = br.readLine()) != null){
lineStr = lineStr.replaceAll(" ", "");
for(int i=0;i<lineStr.length();i++){
if(isNumber(lineStr.charAt(i))){
s += String.valueOf(lineStr.charAt(i));
}else{
if(s != ""){
strList.add(s);
s = "";
}
}
if(i == lineStr.length()-1){
strList.add(s);
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(br != null){
br.close();
br = null;
}
if(fr != null){
fr.close();
fr = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
String outLine = "";
for(int i = 1;i <= strList.size();i++){
outLine += (getNumbers(strList.get(i-1)))+"、";
if(i%3 == 0){
if(outLine.endsWith("、")){
outLine = outLine.substring(0,outLine.length()-1);
}
System.out.println(outLine);
outLine = "";
}
}
}
static boolean isNumber(char c){
if(c >= '0' && c <= '9'){
return true;
}
return false;
}
static String getNumbers(String s){
List<String> numList = new ArrayList<String>();
for(int i = 0;i<10;i++){
numList.add(String.valueOf(i));
}
for(int i = 0;i<s.length();i++){
char c = s.charAt(i);
for(int j = 0;j<numList.size();j++){
if(numList.get(j).equals(String.valueOf(c))){
numList.remove(j);
}
}
}
String retVal = "";
for(String str:numList){
retVal += str;
}
return retVal;
}
}输出:1345689、1345689、1345689
345689、01234789、1245678
1578、014568、1234568
124568、01235679、02345689
0234568、0123458、0123568
23568、0134579、035678
3568、0245679、02345679
03579、1234678、0123468
12348、1246789、0124569
1456、0124678、012679
0129、1234679、0134678
03468、0246789、0123468
12346、1345689、0234568
3458、01234789、01234679
134679、01245678、01356789
06789、0124689、0135679
0356、12345789、1234679
24679、02346789、0124567
0147、02345678、1256789
125689、045679、0234569
023469、2346789、0123569
0256、0123459、024689
02689、0235689、0124578
12578、0123579、1234579
1459、0356789、1345689
1458、0235689、0134679
0146、0123469、0246789
24689、0124569、0124679
01469、0123456、0245678
02458、01236789、02356789
ChangeNumbersNew.javaimport java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;public class ChangeNumbersNew {
static List<String> strList = new ArrayList<String>();
public static void main(String[] args) {
File f = new File("out.txt");
FileReader fr = null;
BufferedReader br = null;
try {
fr = new FileReader(f);
br = new BufferedReader(fr);
String lineStr = "";
String s = "";
while((lineStr = br.readLine()) != null){
lineStr = lineStr.replaceAll(" ", "");
for(int i=0;i<lineStr.length();i++){
if(isNumber(lineStr.charAt(i))){
s += String.valueOf(lineStr.charAt(i));
}else{
if(s != ""){
strList.add(s);
s = "";
}
}
if(i == lineStr.length()-1){
strList.add(s);
s = "";
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(br != null){
br.close();
br = null;
}
if(fr != null){
fr.close();
fr = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
String outLine = "";
for(int i = 1;i <= strList.size();i++){
outLine += (getNumbers(strList.get(i-1)))+"、";
if(i%3 == 0){
if(outLine.endsWith("、")){
outLine = outLine.substring(0,outLine.length()-1);
}
System.out.println(outLine);
outLine = "";
}
}
}
static boolean isNumber(char c){
if(c >= '0' && c <= '9'){
return true;
}
return false;
}
static String getNumbers(String s){
List<String> numList = new ArrayList<String>();
for(int i = 0;i<10;i++){
numList.add(String.valueOf(i));
}
for(int i = 0;i<s.length();i++){
char c = s.charAt(i);
for(int j = 0;j<numList.size();j++){
if(numList.get(j).equals(String.valueOf(c))){
numList.remove(j);
}
}
}
String retVal = "";
for(String str:numList){
retVal += str;
}
return retVal;
}
}输出:1345689、1345689、1345689
03456789、01234789、1245678
0135789、014568、1234568
01245678、01235679、02345689
0234568、0123458、0123568
2345678、0134579、035678
2345689、0245679、02345679
0135789、1234678、0123468
123489、1246789、0124569
1345678、0124678、012679
0123459、1234679、0134678
0234689、0246789、0123468
1234567、1345689、0234568
1345789、01234789、01234679
1345679、01245678、01356789
0246789、0124689、0135679
0234568、12345789、1234679
0246789、02346789、0124567
0134789、02345678、1256789
012345689、045679、0234569
0234689、2346789、0123569
0245678、0123459、024689
0235689、0235689、0124578
1235789、0123579、1234579
0145689、0356789、1345689
0124578、0235689、0134679
012468、0123469、0246789
1234689、0124569、0124679
0134689、0123456、0245678
0124589、01236789、02356789