try (Scanner scanner = new Scanner((new FileReader("names-with re.txt")))) { scanner.useDelimiter(",|\\n"); while (scanner.hasNextLine()) { String s = scanner.next(); scanner.skip(scanner.delimiter()); int age = scanner.nextInt(); System.out.println(s); System.out.println(age); } }
public static String LongestWord() { String[] words = {"Apple", "cheese", "Mississippi", "beer", "hand", "sandwich", "kadabra"}; String maxLength = words[0]; String newString = ""; for (String str : words) { for (int i = 0; i < str.length(); i++) { { for (int j=i+1; j<str.length(); j++){ ="" if="" (str.charat(i)="=" str.charat(j)){ ="" newstring+="str.charAt(i); " } ="" } ="" (newstring.length()=""> maxLength.length()) { maxLength = newString; } } return maxLength; }
public static String LongestWord() { String[] words = {"Apple", "cheese", "Mississippi", "beer", "hand", "sandwich", "kadabra"}; String maxLength = words[0]; String newString = ""; for (String str : words) { for (int i = 0; i < str.length(); i++) { { for (int j=str.length()-1; j>=0; j--){ if (str.charAt(i) == str.charAt(j)){ newString+=str.charAt(i); } } } } if (newString.length() > maxLength.length()) { maxLength = newString; } } return maxLength; }