Java Program to generate a random number from an array

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
To generate a random number, create a Random object and use nextInt(). The same works for array as well.Let us first create an array and add elements −int[] arr = new int[] { 10, 30, 45, 60, 78, 99, 120, 140, 180, 200};Now, get a random number from array by including the above mentioned array’s length under nextInt() −arr[new Random().nextInt(arr.length)]Example Live Demoimport java.util.Random; public class Demo {    public static void main(String... args) {       int[] arr = new int[] { 10, 30, 45, 60, 78, 99, 120, 140, 180, 200};       System.out.print("Random number from the array = "+arr[new Random().nextInt(arr.length)]);    } }OutputRandom number from the array = 45

Need of long data type in C

Anvi Jain
Updated on 30-Jul-2019 22:30:25
In C or C++, there are four different datatypes, that are used for integer type data. These four datatypes are short, int, long and long long. Each of these datatypes takes different memory spaces. The size varies in different architecture and different operating systems. Sometimes int takes 4-bytes or sometimes it takes 2-bytes. This also happen for the compilers. So we can use cross compilers.The cross compilers are basically a compiler, which is capable of compiling for a platform other than current platform.So if we want to compile the following code in 32bit system, and 64-bit system, it will generate ... Read More

What are __FILE__, __LINE__, and __FUNCTION__ in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:25
Here we will see what are the __FILE, __LINE__ and __FUNCTION__ in C++.The __FILE__This macro is used to get the path of the current file. This is useful when we want to generate log files. The following code will explain its functionality.Example#include using namespace std; int errorLog (const char* file, const std::string& msg){    cerr

What is the meaning of medical examination?

Sashi K
Updated on 30-Jul-2019 22:30:25
A medical examination is nothing but going through professional investigations for the body to check for any signs of disease. A typical medical examination includes blood tests, urine tests, chest X-ray, and physical check-up of eyes, nose, ears, lymph nodes, lungs, and abdomen.Mostly medical examinations are required when we apply for a visa to any country or sometimes required by some employers before they hire the candidate.

Read and Write the stack in 8085 Microprocessor

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
Reading from the StackLet us consider that SP contents the address FC78H, and we want to read information from a stack location. In this case, we are not interested in reading from a location whose address is less than the memory address present in SP. This is because 8085 interprets them as useless information. For example, there is no point in reading useless information from memory location FC75H.SP interprets that, memory locations FC78H, FC79H, ..., FFFFH are all interpreted by 8085 to have useful information. To read from Stack, the instruction is POP in 8085 microprocessor instruction set. Here we ... Read More

How to use checktextview in android?

Nitya Raut
Updated on 30-Jul-2019 22:30:25
Before getting into the example, we should know what checktextview in android is. Check textview is expanded by textview and contains checkable interface. Using Checktextview we can find that, whether a user is clicked on textview or not.This example demonstrate about How to use checktextview in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken CheckedTextView, when user clicked on textview, it will ... Read More

How to create a new collection in MongoDB?

Nancy Den
Updated on 30-Jul-2019 22:30:25
To create a new collection in MongoDB, you need to use createCollection() method.Case 1: The easiest syntax to create a new collection in MongoDB is as follows:db.createCollection(“yourNewCollectionName”);Case 2: The alternative syntax to create a new collection in MongoDB is as follows:db.createCollections(“yourNewCollectionName”, options);The options parameter above can have the following values:capped field which returns boolean type which will either true or false.autoIndexId field which returns boolean type which will either true or false.size field which returns number.max field which returns a number also.From the above values, the autoIndexed is deprecated from MongoDB version 3.4 and 3.2. We are using MongoDB version ... Read More

How to select first and last row record using LIMIT in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:25
Let us first create a table. The query to create a table is as followsmysql> create table FirstAndLastDataDemo    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeAge int    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. The query is as followsmysql> insert into FirstAndLastDataDemo(EmployeeName, EmployeeAge) values('John', 23); Query OK, 1 row affected (0.15 sec) mysql> insert into FirstAndLastDataDemo(EmployeeName, EmployeeAge) values('Bob', 13); Query OK, 1 row affected (0.11 sec) mysql> insert into FirstAndLastDataDemo(EmployeeName, EmployeeAge) values('Larry', 24); Query OK, 1 row affected ... Read More

How to apply forEach tag in JSP?

Samual Sam
Updated on 30-Jul-2019 22:30:25
The tag is a commonly used tag because it iterates over a collection of objects. The tag is used to break a string into tokens and iterate through each of the tokens.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultitemsInformation to loop overNoNonebeginElement to start with (0 = first item, 1 = second item, ...)No0endElement to end with (0 = first item, 1 = second item, ...)NoLast elementstepProcess every step itemsNo1varName of the variable to expose the current itemNoNonevarStatusName of the variable to expose the loop statusNoNoneExample for Tag Example Item The above code will generate the following result −Item 1 Item 2 Item 3 Item 4 Item 5

LocalDate parse() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25
The LocalDate instance can be obtained from a string value using the parse() method in the LocalDate class in Java. This method requires a single parameter i.e. the string which is to be parsed. This string cannot be null. Also, it returns the LocalDate instance obtained from the string value that was passed as a parameter.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDate ld = LocalDate.parse("2019-02-15"); System.out.println("The LocalDate is: " ... Read More