Flames program
Today i tried to write flames program in java.
package com.flames.app;
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your name :");
String first = scanner.next();
System.out.println("Enter your partner name :");
String second = scanner.next();
System.out.println(first + second);
int points = getPoints(first , second);
String res= flames(points);
char result=res.charAt(0);
switch(result){
case 'f':
System.out.println(second+" is ur Friend");
break;
case 'l':
System.out.println(second+" is ur Love");
break;
case 'a':
System.out.println(second+" is ur Affection");
break;
case 'm':
System.out.println("u r going to marry "+ second);
break;
case 'e':
System.out.println(second + " is ur Enemy");
break;
case 's':
System.out.println(second +" is ur Sister");
break;
}
}
public static int getPoints(String first , String second){
int total = 0;
for (int i = 0; i < first.length(); i++) {
for (int j = 0; j < second.length(); j++) {
if(first.charAt(i) == second.charAt(j)){
first = first.replaceFirst(String.valueOf(first.charAt(i)), "#");
second = second.replaceFirst(String.valueOf(second.charAt(j)), "#");
}
}
}
total = first.replace("#", "").length() + second.replace("#", "").length();
return total;
}
public static String flames(int len){
String flames = "flames";
int tempRes = 0;
//Check length > 0
if(len > 0)
//Iterate till flames length greater than one
while(flames.length() !=1 ){
//finding char pos to delete
tempRes = len % flames.length();
if(tempRes !=0){
//Append remaining element after strike and first charater to char before strike.
flames = flames.substring(tempRes) + flames.substring(0 , tempRes-1);
}else{
//If its zero remove last element
flames = flames.substring(0,flames.length()-1);
}
}
return flames;
}
}
package com.flames.app;
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your name :");
String first = scanner.next();
System.out.println("Enter your partner name :");
String second = scanner.next();
System.out.println(first + second);
int points = getPoints(first , second);
String res= flames(points);
char result=res.charAt(0);
switch(result){
case 'f':
System.out.println(second+" is ur Friend");
break;
case 'l':
System.out.println(second+" is ur Love");
break;
case 'a':
System.out.println(second+" is ur Affection");
break;
case 'm':
System.out.println("u r going to marry "+ second);
break;
case 'e':
System.out.println(second + " is ur Enemy");
break;
case 's':
System.out.println(second +" is ur Sister");
break;
}
}
public static int getPoints(String first , String second){
int total = 0;
for (int i = 0; i < first.length(); i++) {
for (int j = 0; j < second.length(); j++) {
if(first.charAt(i) == second.charAt(j)){
first = first.replaceFirst(String.valueOf(first.charAt(i)), "#");
second = second.replaceFirst(String.valueOf(second.charAt(j)), "#");
}
}
}
total = first.replace("#", "").length() + second.replace("#", "").length();
return total;
}
public static String flames(int len){
String flames = "flames";
int tempRes = 0;
//Check length > 0
if(len > 0)
//Iterate till flames length greater than one
while(flames.length() !=1 ){
//finding char pos to delete
tempRes = len % flames.length();
if(tempRes !=0){
//Append remaining element after strike and first charater to char before strike.
flames = flames.substring(tempRes) + flames.substring(0 , tempRes-1);
}else{
//If its zero remove last element
flames = flames.substring(0,flames.length()-1);
}
}
return flames;
}
}
Comments
Post a Comment