Skip to content

07.いろんな式

domanthan edited this page Jun 22, 2020 · 1 revision
/**
 *
 */
package lesson03;

/**
 * @author gridscale
 *
 */
public class Expression {

	static char[] table1 = {'あ', 'ん', 'け'};
	static char[] table2 = {'し', 'る'};

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String s1 = "あいしている!";

		if (!(contains(s1, 'あ') && contains(s1, 'い'))) {
			System.out.println("No!");
		} else {
			System.out.println("Yes");
		}

		char[] cc = {'あ', 'い'};
		if (!(contains(s1, cc ))) {
			System.out.println("No!");
		} else {
			System.out.println("Yes");
		}

		System.out.println(contains(s1, table1));
		System.out.println(contains(s1, table2));

		int i = 99;

		if (++i > 98 + 1) {
			System.out.println("YES");
		} else {
			System.out.println("i ++ > 99 = No" );
		}

		System.out.println("i == ?" + i);

	}

	/**
	 *
	 * @param s
	 * @param c
	 * @return
	 */
	public static boolean contains(String s, char c) {
		// if char c contained in s then return true;
		// otherwise  return false;
		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i) == c) {
				return true;
			}
		}

		return false;
	}

	public static boolean contains(String s, char[] chars) {
		// if any c of chars contained in s then return true;
		// otherwise return false;

		for (char c : chars) {
			if (!contains(s, c)) {
				return false;
			}
		}

		return true;
	}

}

Clone this wiki locally