Here you can find the source of common(Scanner in)
private static String common(Scanner in)
//package com.java2s; //License from project: Open Source License import java.util.Scanner; public class Main { private static String common(Scanner in) { String a = in.nextLine(); String b = in.nextLine(); boolean[] marked = new boolean[26]; for (char c : a.toCharArray()) { int pos = c - 97; marked[pos] = true;/* w w w .ja va2 s.c o m*/ } for (char c : b.toCharArray()) { int pos = c - 97; if (marked[pos]) { return "YES"; } } return "NO"; } }