Subtracting two numbers without using '-' operator

前端 未结 5 2059
北荒
北荒 2021-02-04 17:07

i tried with the following code , but i can\'t understand why it\'s giving me wrong answer. i am computing the 2\'s complement and adding with another no.

#inclu         


        
5条回答
  •  暖寄归人
    2021-02-04 17:45

    import java.util.List;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.Hashtable;
    import java.util.LinkedList;
    import java.util.Scanner;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import javax.xml.soap.Node;
    
    public class mainone {
    
    
    
    
    
     public static void main(String args[]){
    
    
     int a=12;
     int b=4;
     Integer  c=new Integer(b);
     String  d=Integer.toString(c);
     String e="-";
     String f=e.concat(d);
     Integer g=Integer.parseInt(f);
     System.out.println(a+g);
    
    
    
    
    
     }
    
    
    
     }
    

提交回复
热议问题