Answer to Question #53898 in Java | JSP | JSF for b.rajesh
2015-08-03T07:49:35-04:00
In the Byteland country a string "S" is said to super ascii string if and only if count of each character in the string is equal to its ascii value.
In the Byteland country ascii code of 'a' is 1, 'b' is 2 ...'z' is 26.
Your task is to find out whether the given string is a super ascii string or not.
1
2015-08-04T02:32:53-0400
import java.util.ArrayList; import java.util.List; public class SuperString { public static void main(String[] args) { String str = args[0].toLowerCase(); if(str != null) { if(testForSuper(str)) { System.out.println("String " + str + " is a super ascii string"); } else { System.out.println("String " + str + " isn't a super ascii string"); } } } public static boolean testForSuper(String str) { List<Character> checkedLetters = new ArrayList<>(); for(int i = 0; i < str.length(); i++) { char ch = str.charAt(i); int counter = 0; if(checkedLetters.contains(ch)) { continue; } for(int j = i; j < str.length(); j++) { if(str.charAt(j) == ch) { counter++; } } if(counter != (ch - 96)) { return false; } checkedLetters.add(ch); } return true; } }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
Java JSP JSF
Comments
Leave a comment