akshay talathi
BAN USERJava -
public class SmartSubString {
public String checkThirty(String str, int n){
String subString = str.substring(0, n);
int counter= n;
if(Character.isWhitespace(str.charAt(n))){
System.out.println(subString);
return subString;
}
if(! Character.isWhitespace(str.charAt(n))){
for(int iii= subString.length(); iii>0; iii--){
while(Character.isWhitespace(str.charAt(iii))){
String subString2 = subString.substring(0, iii);
System.out.println(subString2);
counter = iii;
return subString2;
}
}
}
System.out.println(subString);
return str.substring(0, counter);
}
public static void main(String []args){
SmartSubString smarty = new SmartSubString();
smarty.checkThirty("Featuring stylish rooms and moorings for recreation boats, Room Mate Aitana is a designer hotel built in 2013 on an island in the IJ River in Amsterdam.", 30);
}
}
import java.util.Scanner;
public class StringDifference {
public void inputString(String checkThisString, String s){
int j = 0;
for(int i=0;i<checkThisString.length();i++){
if(checkThisString.length()!= s.length()){
System.out.println("False");
break;
}
if(checkThisString.charAt(i) != s.charAt(i)){
j++;
if(j ==2){
System.out.println("more difference than 2");
break;
}
}
if(i== checkThisString.length()-1 && j==1){
System.out.println("true");
break;
}
}
}
public void isOneCharDiff(String inputString, String []words){
int counter = 0;
for(int i=0; i<words.length;i++){
String x = words[i];
int wordLength = x.length();
for(int j=0;j<wordLength;j++){
if(inputString.length() != wordLength){
System.out.println("length not equal of " + x +" and " + inputString);
break;
}
if(inputString.charAt(j) != x.charAt(j)){
counter++;
if(counter == 2){
System.out.println("More than 2 different characters between strings " + x + " and " + inputString);
counter = 0;
break;
}
}
if(j == inputString.length()-1 && counter ==1){
System.out.println("one difference found between String " + x + " and " + inputString);
counter = 0;
break;
}
}
}
}
public static void main(String[] args) {
//string difference
StringDifference stringDifference = new StringDifference();
Scanner scanner = new Scanner(System.in);
System.out.println("Enter String to compare ! \n");
String checkThisString = scanner.nextLine();
System.out.println("Enter String to be compared ! \n");
String s = scanner.nextLine();
stringDifference.inputString(checkThisString, s);;
String wordsArray[] = { "bananaa","bannna","bannan", "mmmmmm"};
stringDifference.isOneCharDiff(checkThisString, wordsArray);
}
}
Java code:
Please give remarks/feedback.
Thanks!
- akshay talathi October 16, 2015