Java Math copySign ()

Metode Java Math copySign () kopē otrā argumenta zīmi un piešķir tai pirmajam argumentam.

Metodes sintakse copySign()ir šāda:

 Math.copySign(arg1, arg2)

Šeit copySign()ir statiska metode. Tādējādi mēs piekļūstam metodei, izmantojot klases nosaukumu Math,.

copySign () parametri

copySign()Metode ņem divus parametrus.

  • arg1 - pirmais arguments, kura zīme ir jāaizstāj
  • arg2 - otrais arguments, kura zīme tiek nokopēta arg1

Piezīme : Datu veidi ARG1 un ARG2 vajadzētu būt vai nu float, vai double.

copySign () Atgriezt vērtības

  • atgriež pirmo argumentu arg1 ar otra argumenta zīmi arg2

Piezīme . Argumentiem (arg1, -arg2) metode atgriež -arg1 .

Piemērs: Java Math.copySign ()

 class Main ( public static void main(String() args) ( // copy sign of double arguments double x = 9.6d; double y = -6.45; System.out.println(Math.copySign(x, y)); // -9.6 // copy sign of float arguments float a = -4.5f; float b = 7.34f; System.out.println(Math.copySign(a, b)); // 4.5 ) )

Šeit, kā redzat, copySign()metode piešķir otro mainīgo ( y un b ) zīmi pirmajiem mainīgajiem ( x un a ).

Interesanti raksti...