Addition of TWO numbers WITHOUT USING " + " Sign

import java.util.*;
public class Main{

     public static void main(String []args){
       Scanner sc=new Scanner(System.in);
       int f,s;
       System.out.println("Enter first number");
       f=sc.nextInt();
       System.out.println("Enter second number");
       s=sc.nextInt();
     
       if(f>s)
       {
           while(s>0)
           {
               f++;
               s--;
           }
           System.out.println("Sum ="+f);
       }
       else
       {
            while(f>0)
            {
                s++;
                f--;
            }
            System.out.println("Sum ="+s);
       }
     
     
     }
}



Comments

Popular Posts