How to convert a positive number to negative in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
      int x = 8972;
       
      System.out.println(x);
       
      x = x * -1;   
 
      System.out.println(x);
    }
}
 
 
  
  
/*
run:
  
8972
-8972
  
*/

 



answered May 9, 2022 by avibootz
edited May 9, 2022 by avibootz

Related questions

1 answer 130 views
1 answer 130 views
1 answer 127 views
1 answer 153 views
1 answer 129 views
1 answer 119 views
...