When to Use i++ or ++i in C++

Samual Sam
Updated on 26-Jun-2020 07:36:30

1K+ Views

Increment operators are used to increase the value by one while decrement works opposite. Decrement operator decrease the value by one.Pre-increment (++i) − Before assigning the value to a variable, the value is incremented by one.Post-increment (i++) − After assigning the value to a variable, the value is incremented.Here is the syntax of i++ and ++i in C++ language,++variable_name; // Pre-increment variable_name++; // Post-incrementHere,variable_name −Name of the variable given by user.Here is an example of pre and post increment in C++ language,Example Live Demo#include using namespace std; int main() {    int i = 5;    cout

What is a Nebula and How is it Formed

Shanmukh Pasumarthy
Updated on 26-Jun-2020 07:36:01

652 Views

A nebula is an interstellar cloud of dust made of hydrogen, helium and other ionized gasses. Initially, it was a name given for any diffuse cosmic object, including galaxies past the Milky Way.Most nebulae are of the tremendous size, even a great many light years in diameter. The nebula that is scarcely noticeable to the human eye from Earth would seem bigger, yet not brighter, when near it. The Orion Nebula, the brightest cloud in the sky that involves an area double the diameter of the full Moon, can be seen with the exposed eye yet was missed by early ... Read More

isgreater in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 07:35:55

331 Views

The function isgreater() is used to check that the first argument is greater than the second one or not. It is declared in “math.h” header file in C language. It returns true, if successful, otherwise false.Here is the syntax of isgreater().bool isgreater(value1 , value2);Here, value1 − This is the first argument which will be checked with value2.value2 − This is the second argument which is used to check value1 that is greater or not.Here is an example of isgreater().Example Live Demo#include #include using namespace std; int main() {    int val1 = 28;    int val2 = 8;    bool result; ... Read More

modf Function in C/C++

Samual Sam
Updated on 26-Jun-2020 07:35:27

422 Views

The function modf() is used to split the passed argument in integer and fraction. It is declared in “math.h” header file for the mathematical calculations. It returns the fractional value of passed argument.Here is the syntax of modf() in C language, double modf(double value, double *integral_pointer);Here, value − The value which splits into integer and fraction.integral_pointer − It points the integer part of argument after splitting.Here is an example of modf() in C language, Example Live Demo#include #include int main () {    double val, x, res;    val = 28.856;    res = modf(val, &x);    printf("Integral part of val ... Read More

Overriding Method in Different Package in Java

Chandu yadav
Updated on 26-Jun-2020 07:32:47

1K+ Views

TestedThe benefit of overriding is ability to define a behavior that's specific to the subclass type, which means a subclass can implement a parent class method based on its requirement.In object-oriented terms, overriding means to override the functionality of an existing method.Example Live Democlass Animal {    public void move() {       System.out.println("Animals can move");    } } class Dog extends Animal {    public void move() {       System.out.println("Dogs can walk and run");    } } public class TestDog {    public static void main(String args[]) {       Animal a = new Animal(); // ... Read More

Format a Message with Date in Java

Krantik Chavan
Updated on 26-Jun-2020 07:32:31

763 Views

To format the message with date in Java, we use the MessageFormat class and the Date class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration - The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder ... Read More

Long Style Format for Date with Java MessageFormat Class

Smita Kapse
Updated on 26-Jun-2020 07:31:20

291 Views

To format message with long style format of date in Java, we use the MessageFormat class and the Date class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. ... Read More

Compare Two Strings Lexicographically in Java

George John
Updated on 26-Jun-2020 07:30:58

414 Views

We can compare two strings lexicographically using following ways in Java.Using String.compareTo(String) method. It compares in case sensitive manner.Using String.compareToIgnoreCase(String) method. It compares in case insensitive manner.Using String.compareTo(Object) method. It compares in case sensitive manner.These methods returns the ascii difference of first odd characters of compared strings.Example Live Demopublic class Tester {    public static void main(String args[]) {       String str = "Hello World";       String anotherString = "hello world";       Object objStr = str;       System.out.println( str.compareTo(anotherString) );       System.out.println( str.compareToIgnoreCase(anotherString) );       System.out.println( str.compareTo(objStr.toString()));    } }Output-32 0 0

CopyOnWriteArrayList Class in Java Programming

Ankith Reddy
Updated on 26-Jun-2020 07:29:45

266 Views

Class declarationpublic class CopyOnWriteArrayList extends Object implements List, RandomAccess, Cloneable, SerializableCopyOnWriteArrayList is a thread-safe variant of Arraylist where operations which can change the arraylist (add, update, set methods) creates a clone of the underlying array.CopyOnWriteArrayList is to be used in Thread based environment where read operations are very frequent and update operations are rare.Iterator of CopyOnWriteArrayList will never throw ConcurrentModificationException.Any type of modification to CopyOnWriteArrayList will not reflect during iteration since the iterator was created.List modification methods like remove, set and add are not supported in iteration. These method will throw UnsupportedOperationException.null can be added to the list.CopyOnWriteArrayList MethodsFollowing is ... Read More

Convert String to Long in Java

karthikeya Boyini
Updated on 26-Jun-2020 07:29:06

312 Views

To convert String to long, the following are the two methods.Method 1The following is an example wherein we use parseLong() method.Example Live Demopublic class Demo {    public static void main(String[] args) {       String myStr = "5";       Long myLong = Long.parseLong(myStr);       System.out.println("Long: "+myLong);    } }OutputLong: 5Method 2The following is an example wherein we have used valueOf() and longValue() method to convert String to long.Example Live Demopublic class Demo {    public static void main(String[] args) {       String myStr = "20";       long res = Long.valueOf(myStr).longValue();       System.out.println("Long: "+res);    } }OutputLong: 20

Advertisements