Print the number, whose value greater the sum of digits of respective numbers

import java.io.*;
import java.util.*;
public class PracticeDemo {
public static int sumOfDigits(int number){
int remainder1=0,value=0,sum=0,num=number;
do{
remainder1=num%10;
sum+=remainder1;
value=num/10;
num=value;
}while(value>=10);
sum=sum+value;
return sum;
}
public static void main(String [] args){
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();
int first=0,second=0;
int x=0,j=0,count=0;
for(int i=0;i<input.length();i++){
if(String.valueOf(input.charAt(i)).equals(" ")){
j=i;
count++;
}
}
first=Integer.parseInt(input.substring(x,j+1-count));
x=j+1;
second=Integer.parseInt(input.substring(x,input.length()));
int firstSum=0,secondSum=0;
firstSum=sumOfDigits(first);
secondSum=sumOfDigits(second);
if(firstSum>secondSum)
System.out.print(first);
else if(firstSum==secondSum)
System.out.print("Equal");
else
System.out.print(second);
sc.close();
}
}
view raw DraftedPost1 hosted with ❤ by GitHub

Comments

Popular posts from this blog

Reasoning-Number Series

Profit and Loss

Reasoning-Letter Series