random java

Java
import java.util.Random();
Random <name> = new Random();
<variable> = <name>.nextInt(<excuslive top limit>);public class HelloWorld {
  public static void main(String[] args) {
    
    
    // triangular number - first 10
    int x = 1;
    int triangularNumber = 1;
    
    
    while(x < 10)
    {
    
    	System.out.println(triangularNumber);
    	
    	x++;
    	
    	triangularNumber = triangularNumber + x;
    }
    
    
 
  }
}
import java.util.Arrays;

public class HelloWorld {
  public static void main(String[] args) {
    
    // init array
    String[] family = new String[] {"Nova", "Mpo", "Moms", "Shorty", "Charlie"};
    
    // print array string
    System.out.println(Arrays.toString(family));
    
 
  }
}
public class GuessTheNumber {
  public static void main(String[] args) {
    
    
    int randomInt = (int)(20.0 * Math.random());
    int num1 = randomInt;
    int num2 = 10;
    
    if(num1 == num2){
    	System.out.println("Correct!");
    } else if(num1 > num2){
    	System.out.println("Too low!");
    } else{
    	System.out.println("Too high!");
    }
    
    
  }
}package com.example.guessthenumber;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity {


    int randomNumber;

    public void generateRandomNumber(){

        Random rand = new Random();
        randomNumber = rand.nextInt(20) + 1;

    }

    public void GuessTheNumber(View view){


        EditText numberET = (EditText) findViewById(R.id.numerEditText);

        int guessValue = Integer.parseInt(numberET.getText().toString());

        String message;

        if(guessValue > randomNumber)
        {
            message = "Lower!";
        }
        else if (guessValue < randomNumber)
        {
            message = "Higher!";
        }
        else
        {
            message = "Good Guess!!!  Try Again";

            generateRandomNumber();
        }

        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();

        Log.i("Entered Text", numberET.getText().toString());

        Log.i("Random Number", Integer.toString(randomNumber));

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        generateRandomNumber();

    }
}

Source

Also in Java: