Question: Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one

Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in t. Example: Input: s = "abcd" t = "abcde" Output: e JAVA language

class LongString{ public static String longest(String s1, String s2) { int[] chars = new int[26]; for (char c : s1.toCharArray()) { chars[c-'a']=1; } for (char c : s2.toCharArray()) { chars[c-'a']=1; } StringBuilder result = new StringBuilder(26); for (int i = 0; i < chars.length; i++) { if (chars[i] > 0) result.append ((char)(i+'a')); } return result.toString(); } public static void main(String[] args){ System.out.println(result.toString());

} }

please rectify errors and explain how to actually write main method in JAVA

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!