I have a String 9899100101103104105 i want to add consecutive numbers i.e 98+99+100...So i am able to cut the numbers from the String and add upto 100.But after that i am sure how to write the logic.I am using String subString() method and i have seen that (0,2),(2,4),(4,7),(7,10),(10,13),(13,16) should be the substring start and end digits.After (4,7) i am not able to proceeed, here is my logic
public class MissingNumberInString {
public static void main(String[] args) {
String numbr = "9899100101103104105";
firstTwo(numbr);
}
public static void firstTwo(String str) {
int sum =0;
int num = 0;
for(int i=0;i<str.length()-1;i=i+2){
if(sum <=99){
sum += Integer.parseInt(str.substring(i, i+2));
}else{
sum += Integer.parseInt(str.substring(i, i+3));
}
System.out.println(sum);
}
}
}
in else part after (4,7) i am not able to proceed ,please help
ibased on thesum < = 99too, you can't increment by 2 after 99...