Try This:
Apex Page:
<apex:page docType="html-5.0" controller="testing">
<apex:form >
<apex:input value="{!addthis}"/>
<apex:commandButton action="{!add}" value="Add"/>
<apex:outputLabel >{!result}</apex:outputLabel>
</apex:form>
</apex:page>
Controller:
public class testing {
public Integer result { get; set; }
public String addthis{get; set;}
public List<Integer> IntList = new List<Integer>();
public PageReference add() {
Integer sum = 0;
List<String> str = addthis.replace(' ','').split(',');
for(String s : str){
Integer i = Integer.ValueOf(s);
sum = sum +i;
}
result = sum;
return null;
}
}
Update: If you want result in same input text:
Page:
<apex:page docType="html-5.0" controller="testing">
<apex:form >
<apex:input value="{!addthis}"/>
<apex:commandButton action="{!add}" value="Add"/>
</apex:form>
</apex:page>
Controller:
public class testing {
//public Integer result { get; set; }
public String addthis{get; set;}
public List<Integer> IntList = new List<Integer>();
public PageReference add() {
Integer sum = 0;
List<String> str = addthis.replace(' ','').split(',');
for(String s : str){
Integer i = Integer.ValueOf(s);
sum = sum +i;
}
addthis = sum+'';
return null;
}
}