Abhinaw Bhagat
BAN USERpackage amazon;
public class SumOfAllNumInString {
public static void main(String[] args) {
String s = "11aa22b01b33dd44";
int n =0,sum=0;
for(char x :s.toCharArray()){
if(x>=48 && x<=57){
n = (n*10)+(x-48);
}else{
sum+=n;
n =0;
}
}
System.out.println(sum+n);
}
}
package arrays;
public class OnlyAOnlyBArrayElements {
public static void main(String[] args) {
int[]a={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int[]b={1,3,5,7,9,11,13,15};
int[]temp = new int[128];
for(int i=0;i<a.length;i++){
temp[a[i]]++;
}
for(int i=0;i<b.length;i++){
if(temp[b[i]]==0){
System.out.print(b[i]);
}
}
System.out.println();
temp = new int[128];
for(int i=0;i<b.length;i++){
temp[b[i]]++;
}
for(int i=0;i<a.length;i++){
if(temp[a[i]]==0){
System.out.print(a[i]);
}
}
}
}
- Abhinaw Bhagat July 28, 2016