Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

float in Java example code

Android development
Java float is 32 bit single precision type and used when fractional precision calculation is required.

Java float je 32 bitů veliké číslo sloužící především pro přesný výsledek za desetinnou tečkou například při dělení čísel. Pro větší přesnost použíijte 64 bitový typ Double.


		// declaration and assignment of value  type float
		float x = 18.41785f;
		//print formated  value
		System.out.printf("The value of x is %.3f%n", x); // 18.418
                
                // declaring more variables in single statement
                float f1 = 12.4F, f2 = 564.5F, f3 = 14.589F;

		// float range of value
		System.out.println(Float.MIN_VALUE); // 4E-45
		System.out.println(Float.MAX_VALUE); // 4028235E38

		// is NaN  Not-a-Number
		float f = (float) Math.sqrt(-15);
		boolean bNaN = Float.isNaN(f);
		System.out.print(bNaN); // true
		
                // check if a string is a valid number in Java example
                // convert string to float Java example
		String sF = "12.8";
		float fParse = Float.parseFloat(sF);

	       // convert strings to numbers
	      String sFl = "15.48";
	      float fFromString = (Float.valueOf(sFl)).floatValue();

// float to string in Java example code
Float fObj = new Float(68.5);
String str = fObj.toString();
// else 
Float fS = 11.6f;
String sFloat = fS.toString();

              // compare two float variables
	      Float fComp1 = 4.3f;
	      if(fComp1.equals(4.3f))
	  		System.out.print("true");

	    // compares the two specified float values in Java example
	    int i =	Float.compare(11.5f, 11.7f); // -1 first < second
	    // 0 first == second
	    // 1 first > second
	    System.out.print(i);



396LW NO topic_id




AD

Další témata ....(Topics)


79

ArrayList Collections Add new Item Sort Find Item Java example | arraylist-collection-sort-add-java-example


How add item to ArrayList, sort ArrayList, search find index of item in ArrayList, min(), max() Java basic example.

import java.util.ArrayList;
import java.util.Collections;

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "End" };
		   ArrayList<String> arrayList = new ArrayList<String>();
            for(String s: arrayOfString)
		     arrayList.add(s);

		    Collections.sort(arrayList);
		    // foreach
		    for (String str: arrayList)
		      System.out.println(str);
		    
		    Object objMin = Collections.min(arrayList);
		    System.out.println("Min is: " + objMin);
		    
		    Object objMax = Collections.max(arrayList);
		    System.out.println("Max is: " + objMax);
		    
		    int index = Collections.binarySearch(arrayList, "people");
		    System.out.println("Index of people is: " + index);
		    
		  }

		
	
}
/*
End
Hello
bye-bye
hello
nothing
people
world!
Min is: End
Max is: world!
Index of people is: 5
*/
206

ADT 20 Eclipse New Activity wizard cannot be complete due to support library | adt-20-eclipse-new-activity-wizard-cannot-be-complete-due-to-support-library


Issue:
When using New Activity wizard, ADT 20 asked to install Android Support library version 8 even though version 9 has been installed.

Pressing "Install/Update" then ADT popup a window downloading Support library, when finished nothing happen.
Pressing "Check Again" does nothing.
If i restarting Eclipse again this problem.

Notice: If you install new version ADT or update via SDK Manager, open SDK Manager standalone and close Eclipse.
Workaround:
- Close Eclipse
- Open SDK Manager standalone (c:\Program Files\Android\android-sdk-windows\SDK Manager.exe)
- Check the checkbox and uninstall Extras -> Android Support Library.
- Check again Extras -> Android Support Library and install it
- Restart Eclipse
- Try to create new project

android/new-activity-adt-20-issue.png

android/adt-20-support-library.png
35

Android startup tutorial for developers video | android-startup-tutorial-for-developers-video


How install Android emulator on PC
//developer.android.com/sdk/installing.html

Download links:
Java Development Kit JDK download
Eclipse download
Android SDK download