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.

Random number Java


AD MOB

Generate random number Android Java example source code.

		Random rand = new Random();
		int i = rand.nextInt() % 256; // range -255  +255
		System.out.print(i + "

"); // -184 i = Math.abs(rand.nextInt() % 12); // range 0 +11 System.out.print(i); // 7



// Math.random() start with 0.  e.g. 0.35981234 
int nRan = (int) (Math.random()*10); // 0 - 10

// nextDouble(), nextFloat(), nextInt(), nextLong() returns 0 - 10
import java.util.Random;´

Random r = new Random();
int nRan = r.nextInt(); // 0 - 10
double dRan = r.nextDouble() * 10; // e.g. 7.496285271597397

nextDouble – return 0 - 1
nextFloat – same as double
nextInt –  -2147483648  +2147483647
nextLong –  -922337203685775808  +9223372036854775807
nextGaussian –  0.0 aberation 1.0.

397LW NO topic_id




AD

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


75

The Labeled continue statement Java example | the-labeled-continue-statement-java-example


The Labeled continue statement as goto Java example.


public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = { "Hello", "people", "hello", "world!" };
		OuterLoop: for (int e = 0; e < 4; e++) {
			for (int i = 0; i < arrayOfString.length; i++) {
				if (arrayOfString[i].equals("hello"))
					continue OuterLoop;
				System.out.println(arrayOfString[i]);
			}
		}
	}
}
/*
Hello
people
Hello
people
Hello
people
Hello
people
*/
192

Samsung Galaxy Pocket - Android | samsung-galaxy-pocket-android


Nejmenší telefon od Samsungu s Androidem se někdy přidává i jako dárek k zakoupenému zboží, přesto tento telefon toho za svou cenu něco přes 2 000 korun umí hodně.
Technické parametry Samsung Galaxy Pocket
Rozměry a hmotnost: 103,70 × 57,50 × 12 mm, 97 g
Sítě GSM 850 / 900 / 1800 / 1900 MHz, W-CDMA (3G) 900 MHz / 2 100 MHz
Displej TFT TN, 2,80" (320 × 240 px), dotykový: kapacitní
Procesor 832 MHz
Paměť RAM 256 MB, vnitřní paměť 3 GB, paměťové karty microSD
Operační systém Android 2.3, údajně nelze upgradovat
Hudba: mp3, aac, wav, wma
Video: mp4, 3gp, 320 × 240 px, 15 FPS
Fotoaparát 2 Mpx
Navigace vestavěná GPS, elektronický kompas
Baterie 1 200 mAh, pohotovostní doba: 312 hodin
Cena něco přes 2 000 korun / léto 2012

samsung-galaxy-pocket
104

Unable to find explicit activity class Android Eclipse error | unable-to-find-explicit-activity-class-android-eclipse-error


android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.my_package/com.example.my_package.MainClass}; have you declared this activity in your AndroidManifest.xml?

Is MainClass.java in AndroidManifest as a activity ?
AndroidManifest.xml example

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="//schemas.android.com/apk/res/android"
      package="com.example.my_packag"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainClass"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>
72

While cycle loop in Java example | while-cycle-loop-in-java-example


While cycle Java basic example with array of strings.

MainClass.java

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = { "Hello", "people", "hello", "world!" };
                int i = 0;
		while ( i < arrayOfString.length ){
			System.out.println(arrayOfString[i]);
			i++;
		}
	}
}
100

How evaluate any expression in Eclipse debugger editor Android example | how-evaluate-any-expression-in-eclipse-debugger-editor-android-example


Tutorial by pictures how evaluate a variable in Eclipse debugger window.

1.) Open Debug perspective in Eclipse and to start debugging a Activity.
eclipse-debug-perspective


2.) Open Display window from menu Window->Show view->Display

eclipse dislplay window

3.) Set breakpoint where you need to evaluate a variable.

eclipse-toggle-breakpoint

4.) Debug the Activity to breakpoint.

eclipse-debugger-breakpoint


5.) Into the Display window type code for evaluate your variable and execute code.

eclipse-type-evaluate-code-to-display-window


6.) Check if change of value a variable

eclipse-evaluate-a-variable



Editace: 2013-12-09 10:54:07
Počet článků v kategorii: 397
Url:random-number-java

AD
11 Share
Share
Tweet