Results 1 to 3 of 3

Thread: Java :

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Eclipse Plugin Developer aphex's Avatar
    Join Date: Mar:2003
    Location: Karlsruhe
    Posts: 546

    Java :

    ,
    , Math.sqrt() , . java.lang.Math.abs(), . .

    !


    Code:
    public static int squareRoot(int x) {		
    	int zahler=0, versuch;
    	do {
    		zahler = zahler +1;
    		versuch = zahler*zahler;
    		} 
    	while (x>=versuch);
    	if (java.lang.Math.abs(versuch-x)>java.lang.Math.abs((zahler-1)*(zahler-1)-x)){
    		versuch= (zahler-1);
    		return versuch;
    		} 
    	else	
    	return zahler;

  2. #2
    Registered User Annihilator's Avatar
    Join Date: Jun:2004
    Location: Sofia
    Posts: 1,316
    Code:
    Math.abs(int i)
    Code:
    i < 0 ? -i : i

  3. #3
    Eclipse Plugin Developer aphex's Avatar
    Join Date: Mar:2003
    Location: Karlsruhe
    Posts: 546
    , ! :
    Code:
    public static int betrag(int x){  
    	if (x<0) x=-x;
    	return x;
    	
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |