Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java . util .Scanner;
- class Ac{
- static void acceptData(){
- String str="";
- int sum=0,sum1=0;
- System.out.println("Enter the String ::");
- Scanner in = new Scanner(System.in);
- str = in.nextLine();
- char ch[] = str.toCharArray();
- int ch1[] = new int[ch.length];
- int a[] = new int[ch1.length];
- for(int i=0;i<ch.length;i++)
- System.out.print(ch[i]);
- for(int i=0;i<ch.length;i++)
- {
- ch1[i] = java.lang.Integer.parseInt(String.valueOf(str.charAt(i)));
- }
- for(int j=0;j<ch1.length;j++)
- {
- if(j==0 || j%2==0)
- sum+=ch1[j];
- else
- sum1+=ch1[j];
- }
- System.out.println("Sum::" + sum);
- System.out.println("Sum1::" + sum1);
- }
- public static void main(String args[]){
- acceptData();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment