Java Math negateExact () yöntemi, belirtilen sayının işaretini ters çevirir ve döndürür.
negateExact()Yöntemin sözdizimi şöyledir:
Math.negateExact(num)
İşte negateExact()statik bir yöntem. Bu nedenle, sınıf adını kullanarak yönteme erişiyoruz Math.
negateExact () Parametreler
negateExact()Yöntem, tek bir parametre alır.
- num - işareti tersine çevrilecek argüman
Not : Bağımsız değişkenin veri türü ya intda olmalıdır long.
negateExact () Dönüş Değeri
- Belirtilen argümanın işaretini ters çevirdikten sonra değeri döndürür
Örnek 1: Java Math.negateExact ()
class Main ( public static void main(String() args) ( // create int variables int a = 65; int b = -25; // negateExact() with int arguments System.out.println(Math.negateExact(a)); // -65 System.out.println(Math.negateExact(b)); // 25 // create long variable long c = 52336L; long d = -445636L; // negateExact() with long arguments System.out.println(Math.negateExact(c)); // -52336 System.out.println(Math.negateExact(d)); // 445636 ) )
Yukarıdaki örnekte, ilgili değişkenlerin işaretini tersine çevirmek için Math.negateExact()yöntemi intve longdeğişkenleriyle kullandık.
Örnek 2: Math.negateExact () Özel Durum Atar
negateExact()Reddi sonucu veri türü taşmaları, bu yöntem bir durum oluşturur. Yani, sonuç, belirtilen değişkenlerin veri türünün aralığı içinde olmalıdır.
class Main ( public static void main(String() args) ( // create a int variable // minimum int value int a = -2147483648; // negateExact() with the int argument // throws exception System.out.println(Math.negateExact(a)); ) )
Yukarıdaki örnekte, a'nın intdeğeri minimum değerdir. Burada negateExact()yöntem a değişkeninin işaretini değiştirir.
-(a) => -(-2147483648) => 2147483648 // out of range of int type
Dolayısıyla, negateExact()yöntem integer overflowistisnayı atar .
Önerilen Eğitimler
- Math.incrementExact ()
- Math.decrementExact ()








