Programming Articles

Page 791 of 2544

Using reflection to check array type and length in Java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 2K+ Views

The array type can be checked using the java.lang.Class.getComponentType() method. This method returns the class that represents the component type of the array. The array length can be obtained in int form using the method java.lang.reflect.Array.getLength().A program that demonstrates this is given as follows −Exampleimport java.lang.reflect.Array; public class Demo {    public static void main (String args[]) {       int[] arr = {6, 1, 9, 3, 7};       Class c = arr.getClass();       if (c.isArray()) {          Class arrayType = c.getComponentType();          System.out.println("The array is of type: " ...

Read More

"." custom specifier in C#

Samual Sam
Samual Sam
Updated on 11-Mar-2026 260 Views

The "." custom format specifier adds a localized decimal separator into the output string.The 1st period in the format string determines the location of the decimal separator in the formatted value.double d = 2.3; d.ToString("0.00", CultureInfo.InvariantCultureLet us see another example to learn how to implement “.” Custom specifier.Exampleusing System; using System.Globalization; class Demo {    static void Main() {       double d;       d = 3.7;       Console.WriteLine(d.ToString("0.00", CultureInfo.InvariantCulture));       Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0:0.00}", d));       d = 5.89;       Console.WriteLine(d.ToString("00.00", CultureInfo.InvariantCulture));       Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0:00.00}", d));    } }Output3.70 3.70 05.89 05.89

Read More

Display Date Time in dd MMM yyyy hh:mm:ss zzz format in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

Firstly, import the following Java packagesimport java.text.SimpleDateFormat; import java.util.Date;Now, create objectsDate dt = new Date(); SimpleDateFormat dateFormat;Displaying date in the format we want −dateFormat = new SimpleDateFormat("dd MMM yyyy hh:mm:ss zzz");The following is an example −Exampleimport java.text.SimpleDateFormat; import java.util.Date; public class Demo {    public static void main(String args[]) {       Date dt = new Date();       SimpleDateFormat dateFormat;       dateFormat = new SimpleDateFormat("dd MMM yyyy hh:mm:ss zzz");       System.out.println("Date: "+dateFormat.format(dt));    } }OutputDate: 22 Nov 2018 07:53:58 UTC

Read More

Size of a Three-dimensional array in C#

George John
George John
Updated on 11-Mar-2026 1K+ Views

To get the size of a 3D array in C#, use the GetLength() method with parameter as the index of the dimensions.GetLength(dimensionIndex)To get the size.arr.GetLength(0) arr.GetLength(1) arr.GetLength(2)Exampleusing System; class Program {    static void Main() {       int[,,] arr = new int[3,4,5];       // length of a dimension       Console.WriteLine(arr.GetLength(0));       Console.WriteLine(arr.GetLength(1));       Console.WriteLine(arr.GetLength(2));       // length       Console.WriteLine(arr.Length);    } }Output3 4 5 60

Read More

C++ Program to Compute Combinations using Factorials

Samual Sam
Samual Sam
Updated on 11-Mar-2026 1K+ Views

The following is an example to compute combinations using factorials.Example#include using namespace std; int fact(int n) {    if (n == 0 || n == 1)    return 1;    else    return n * fact(n - 1); } int main() {    int n, r, result;    coutn;    coutr;    result = fact(n) / (fact(r) * fact(n-r));    cout

Read More

Set a duration in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 193 Views

To set a duration, let us declare two objects of Calendar classCalendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance();Set a time for one of the calendar objectsc2.add(Calendar.HOUR, 9); c2.add(Calendar.MINUTE, 15); c2.add(Calendar.SECOND, 40);Now, find the difference between both the time. One would be the current time and another we declared above −long calcSeconds = (c2.getTimeInMillis() - c1.getTimeInMillis()) / 1000;The following is an example −Exampleimport java.util.Calendar; public class Demo { public static void main(String args[]) {     Calendar c1 = Calendar.getInstance();     Calendar c2 = Calendar.getInstance();     // set hour, minute and second     c2.add(Calendar.HOUR, 9);     ...

Read More

FormatException in C#

Samual Sam
Samual Sam
Updated on 11-Mar-2026 3K+ Views

FomatException is thrown when the format of an argument is invalid.Let us see an example.When we set a value other than int to int.Parse() method, then FormatException is thrown as shown below −Exampleusing System; class Demo {    static void Main() {       string str = "3.5";       int res = int.Parse(str);    } }The following error is thrown when the above program is compiled since we have passed a value other than integer.OutputUnhandled Exception: System.FormatException: Input string was not in a correct format.

Read More

Add seconds to current date using Calendar.add() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

Import the following package for Calendar class in Java.import java.util.Calendar;Firstly, create a Calendar object and display the current date and time.Calendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());Now, let us increment the seconds using the calendar.add() method and Calendar.SECOND constant.calendar.add(Calendar.SECOND, 15);Exampleimport java.util.Calendar; public class Demo {    public static void main(String[] args) {       Calendar calendar = Calendar.getInstance();       System.out.println("Current Date = " + calendar.getTime());       // Add 15 seconds to current date       calendar.add(Calendar.SECOND, 15);       System.out.println("Updated Date = " + calendar.getTime());    } }OutputCurrent ...

Read More

List the Interfaces That a Class Implements in Java

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 727 Views

The interfaces that are implemented by a class that is represented by an object can be determined using the java.lang.Class.getInterfaces() method. This method returns an array of all the interfaces that are implemented by the class.A program that demonstrates this is given as follows −Examplepackage Test; import java.lang.*; import java.util.*; public class Demo {    public static void main(String[] args) {       listInterfaces(String.class);    }    public static void listInterfaces(Class c) {       System.out.println("The Class is: " + c.getName());       Class[] interfaces = c.getInterfaces();       System.out.println("The Interfaces are: " + Arrays.asList(interfaces));   ...

Read More

C# Linq Except Method

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 3K+ Views

Get the difference between two arrays using the Except() method.The following are the two arrays.int[] arr = { 9, 12, 15, 20, 35, 40, 55, 67, 88, 92 }; int[] arr2 = { 20, 35 };To get the difference, use Except() method that returns the first list, except the elements in the second list.arr.AsQueryable().Except(arr2);The following is the entire example.Exampleusing System; using System.Linq; using System.Collections.Generic; class Program {    static void Main() {       int[] arr = { 5, 10, 15, 20, 35, 40 };       int[] except = { 20, 35 };       Console.WriteLine("Initial ...

Read More
Showing 7901–7910 of 25,433 articles
« Prev 1 789 790 791 792 793 2544 Next »
Advertisements