Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.shawon.strings;
- import java.util.StringTokenizer;
- /**
- *
- * @author shawonmajid
- */
- public class StringTest {
- public static void main(String[] args) {
- String str = "12 315 1251 232 2525 end";
- StringTokenizer tok = new StringTokenizer(str);
- int ans = 0;
- while(tok.hasMoreTokens()){
- String cur = tok.nextToken();
- if(!cur.equals("end")){
- ans += Integer.parseInt(cur);
- }
- }
- System.out.println(ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement