Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main (String[] args) throws java.lang.Exception
- {
- Scanner in = new Scanner(System.in);
- String str = in.nextLine();
- int sNum = in.nextInt();
- String parseStr[] = str.split(",");
- Integer[] sequence = new Integer[parseStr.length];
- int k=0;
- for(String s : parseStr){
- sequence[k]=Integer.parseInt(s.trim());
- k++;
- }
- int j = 0;
- Boolean chk = true;
- while (j < sequence.length - 1 && chk) {
- int i = j;
- int sum = 0;
- while (i < sequence.length - 1 && sum <= sNum) {
- sum += sequence[i];
- if (sum == sNum) {
- for (int l = j; l <= i; l++) {
- System.out.print(sequence[l]);
- if (l < i)
- System.out.print(", ");
- else
- System.out.println("");
- }
- chk = false;
- break;
- }
- i++;
- }
- j++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement