I need logic for flames, how to count the word flames
In my code how to delete the string "flames" according to my counter
value..# -please help me with the logic.. -else I have to use substring
method -indexOf method.. -please guide me
let say i have a code
package list;
import java.util.Scanner;
public class flames {
public static void main(String[] args){
String name1;
String name2;
String name12;
Scanner sc = new Scanner(System.in);
System.out.println("enter the name");
name1 = sc.nextLine();
System.out.println("enter the name");
name2 = sc.nextLine();
name12=name1 .concat(name2);
System.out.println("the entire name : "+name12);
char[] sortname = name12.toCharArray();
java.util.Arrays.sort(sortname);
String sorted = new String(sortname);
System.out.println(sortname);
String dup = String.copyValueOf(sortname);
StringBuilder noDupes = new StringBuilder();
for (int i = 0; i < dup.length(); i++) {
String si = dup.substring(i, i + 1);
if (noDupes.indexOf(si) == -1) {
noDupes.append(si);
}
}
System.out.println("remove duplicate: "+noDupes);
int counter = noDupes.length();
System.out.println("the count of string: "+counter);
how to manipulate the flames string according to my counter variable
if(counter == 1) { System.out.println("friends"); }else if(counter == 2){
System.out.println("love"); }else if(counter == 3){
System.out.println("affection"); }else if(counter == 4){
System.out.println("marriage"); }else if(counter == 5){
System.out.println("enemy"); }else if(counter == 6){
System.out.println("sibblings"); }
}
}
No comments:
Post a Comment