I want to assign specific values to alphabets (below in the code) and then calculate its
total added output which is provided by input string, which I am not getting. E.g. Kamran= 2+1+4+2+1+5 = 15 or abc = 1+2+3 = 6.
Via this code I only get the output of the last digit.
Thanks in Advance! Regards!!!
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class p1 {
static int addition;
static char Kamran;
static int string1;
static int total;
final static int a=1,b=2,c=3,d=4,e=5,f=8,g=3,h=5,i=1,j=1,k=2,l=3,m=4,n=5,o=7,p=8,q=1,r=2,s=3,t=4,u=6,v=6,w=6,x=5,y=1,z=7;
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String userInput = in.readLine();
for(int ai=0;ai<userInput.length();ai++){
string1 = (int)userInput.charAt(ai);
}
int adder=0;
if(string1=='k')
{adder = 2 + adder ; }
if(string1=='a')
{adder = 1 + adder ; }
if(string1=='m')
{adder = 4 + adder ; }
if(string1=='r')
{adder = 2 + adder ; }
if(string1=='b')
{adder = 2 + adder ; }
if(string1=='n')
{adder = 5 + adder ; }
total=adder;
System.out.println(total);
}
}
1 Answer