⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_1002_1.java

📁 perking university s ACM answer. ID: 1002
💻 JAVA
字号:
package acm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;

/*
 * acm OF pecking university.
 * ID:1002
 * Subject:487-3279
 * we replace the 'q' and 'z' with '1'~~
 */
public class Main_1002_1 {
	private String telNum;

	// rewrite the toString() method
	public void toString(Vector<?> v1) {
		for (int m = 0; m < 3; m++) {
			System.out.print(v1.elementAt(m));
		}
		System.out.print("-");
		for (int m = 3; m < 7; m++) {
			System.out.print(v1.elementAt(m));
		}
	}

	public static void main(String[] a) throws IOException {
		Main_1002_1 user = new Main_1002_1();
		Main_1002_2 user2 = new Main_1002_2();
		// vector to accept the user's input.
		Vector<Vector<?>> v = new Vector<Vector<?>>();
		BufferedReader bu = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("enter the numbers of the tel~~");
		int vLength = Integer.parseInt(bu.readLine());
		System.out.println("the tel numbers is " + vLength);
		for (int x = 0; x < vLength; x++) {
			user.telNum = bu.readLine();
			// treat every string.
			v.addElement(user2.matchTheNumer(user.telNum));
		}
		// FIXME now we need to sequence and number the telephones.
		// out put the vectors after changing.
		for (int x1 = 0; x1 < vLength; x1++) {
			user.toString(v.elementAt(x1));
			System.out.print("\n");
		}
	}
}





另外一个类:请保存在另外一个class中:
package acm;

import java.io.IOException;
import java.util.Vector;

public class Main_1002_2 {
	public void toString(Vector<Character> v1) {
		for (int m = 0; m < 3; m++) {
			System.out.print(v1.elementAt(m));
		}
		System.out.print("-");
		for (int m = 3; m < 7; m++) {
			System.out.print(v1.elementAt(m));
		}
	}

	public Vector<Character> matchTheNumer(String x) throws IOException {
		char y[] = x.toLowerCase().toCharArray();
		// convert the identifier to the numbers.
		for (int z = 0; z < y.length; z++) {
			if (y[z] == 'a' | y[z] == 'b' | y[z] == 'c') {
				y[z] = '2';
			}
			if (y[z] == 'd' | y[z] == 'e' | y[z] == 'f') {
				y[z] = '3';
			}
			if (y[z] == 'g' | y[z] == 'h' | y[z] == 'i') {
				y[z] = '4';
			}
			if (y[z] == 'j' | y[z] == 'k' | y[z] == 'l') {
				y[z] = '5';
			}
			if (y[z] == 'm' | y[z] == 'n' | y[z] == 'o') {
				y[z] = '6';
			}
			if (y[z] == 'p' | y[z] == 'r' | y[z] == 's') {
				y[z] = '7';
			}
			if (y[z] == 't' | y[z] == 'u' | y[z] == 'v') {
				y[z] = '8';
			}
			if (y[z] == 'w' | y[z] == 'x' | y[z] == 'y') {
				y[z] = '9';
			}
			if (y[z] == 'q' | y[z] == 'z') {
				y[z] = '1';
			}
		}
		// delete the other elements.
		// vector to accept the new array's elements
		Vector<Character> v = new Vector<Character>();
		for (int m = 0; m < y.length; m++) {
			if (y[m] >= 48 && y[m] <= 57) {
				v.addElement(y[m]);
			}
		}
		return v;
		/*
		 * this moment,we have already known that length of the vector is 7, so
		 * we should set the format.
		 */
		// set the format and output,
		// just reWrite the toString() method.
		// this.toString(v);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -