stringinput.java

来自「caculater in the ssd any...asdf sadf」· Java 代码 · 共 49 行

JAVA
49
字号
package bluewater;

import java.io.*;

public class StringInput {

	private static BufferedReader stdIn = new BufferedReader(
			new InputStreamReader(System.in));

	// private static PrintWriter stdOut = new PrintWriter(System.out);

	private static PrintWriter stdErr = new PrintWriter(System.err);

	public static boolean beRight(String x) {
		// the number of ( is not equal the number of )
		int left = 0, right = 0;
		for (int i = 0; i < x.length(); i++) {
			if (x.charAt(i) == '(')
				left++;
			if (x.charAt(i) == ')')
				right++;
		}
		if (left != right){
			stdErr.println("the number of ( is not equal the number of )");
			return false;
		}
		//more another wrong answer
		//to be continue ...
		return true;
	}

	public String input() {
		String b = "";
		boolean f = true;
		while (f) {
			f = false;
			try {
				b = stdIn.readLine();
				if (!beRight(b))
					throw new IOException();
			} catch (IOException e) {
				stdErr.println("input err please input again:");
				f = true;
			}
		}
		return b;
	}
}

⌨️ 快捷键说明

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