Programming Articles

Page 790 of 2544

Return values of printf() and scanf() in C

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

The printf() and scanf() functions are required for output and input respectively in C. Both of these functions are library functions and are defined in the stdio.h header file.Details about the return values of the printf() and scanf() functions are given as follows −The printf() functionThe printf() function is used for printing the output. It returns the number of characters that are printed. If there is some error then it returns a negative value.A program that demonstrates this is as follows −Example#include int main(){    char str[] = "THE SKY IS BLUE";    printf("The value returned by ...

Read More

C# Decimal ("D") Format Specifier

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

The "D" (or decimal) format specifier works for integer type. It converts a number to a string of decimal digits (0-9).Let’say the following is our number.int val = 467;Now to return the result as 0467, use the following decimal format specifier.val.ToString("D4")Let us see another example.Exampleusing System; using System.Globalization; class Demo {    static void Main() {       int val;       val = 877;       Console.WriteLine(val.ToString("D"));       Console.WriteLine(val.ToString("D4"));       Console.WriteLine(val.ToString("D8"));    } }Output877 0877 00000877

Read More

Get the unqualified name of a class in Java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 766 Views

A qualified class name in Java contains the package that the class originated from. In contrast to this, the unqualified class name contains only the class name without any package information. A program that gets the unqualified name of a class is given as follows:Examplepublic class Demo {    public static void main(String[] argv) throws Exception {       Class c = java.util.ArrayList.class;       String className = c.getName();       System.out.println("The qualified class name is: " + className);       if (className.lastIndexOf('.') < 0) {          className = className.substring(className.lastIndexOf('.') + 1);     ...

Read More

Represent Int64 as a String in C#

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

Int64 represents a 64-bit signed integer. To represent it as a string, use the ToString() method.Firstly, declare and initialize an Int64 variable.long val = 8766776;Now, represent it as a string.val.ToString()Let us see the complete example.Exampleusing System; class Demo {    static void Main() {       long val = 8766776;       Console.Write("Long converted to string = "+val.ToString());    } }OutputLong converted to string = 8766776

Read More

C function to Swap strings

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

The following is an example to swap strings.Example#include #include int main() {    char st1[] = "My 1st string";    char st2[] = "My 2nd string";    char swap;    int i = 0;    while(st1[i] != '\0') {       swap = st1[i];       st1[i] = st2[i];       st2[i] = swap;       i++;    }    printf("After swapping s1 : %s", st1);    printf("After swapping s2 : %s", st2);    return 0; }OutputAfter swapping s1 : My 2nd string After swapping s2 : My 1st stringIn the above program, two arrays ...

Read More

Get the fully-qualified name of a class in Java

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

A fully-qualified class name in Java contains the package that the class originated from. An example of this is java.util.ArrayList. The fully-qualified class name can be obtained using the getName() method.A program that demonstrates this is given as follows −Examplepublic class Demo {    public static void main(String[] argv) throws Exception {       Class c = java.util.ArrayList.class;       String className = c.getName();       System.out.println("The fully-qualified name of the class is: " + className);    } }OutputThe fully-qualified name of the class is: java.util.ArrayListNow let us understand the above program.The getName() method is used to ...

Read More

The &quot;0&quot; custom format specifier in C#

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

The “0” custom specifier is a zero placeholder.If the value to be formatted has a digit in the position where the zero appears in the format string, the the digit is copied to the resultant string. However, if this doesn’t happen, then a zero appears.Here is our double variable.double d; d = 292;Now, by setting the following, you can easily make zero appear in the format string.d.ToString("00000")Exampleusing System; using System.Globalization; class Demo {    static void Main() {       double d;       d = 292;       Console.WriteLine(d.ToString("00000"));       Console.WriteLine(String.Format("{0:00000}", d));     ...

Read More

The &quot;#&quot; custom specifier in C#

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 259 Views

The "#" custom format specifier works as a digit-placeholder symbol.If the value to be formatted has a digit in the position where the "#" symbol appears in the format string, then that digit is copied to the resultant string.We have set a double type here.double d; d = 4.2;Now, let us use the “#” custom specifier.d.ToString("#.##", CultureInfo.InvariantCulture)Here are other examples.Exampleusing System; using System.Globalization; class Demo {    static void Main() {       double d;       d = 4.2;       Console.WriteLine(d.ToString("#.##", CultureInfo.InvariantCulture));       Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0:#.##}", d));       d = 345;   ...

Read More

C# Program to find a key in Dictionary

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 354 Views

Firstly, set a Dictionary collection with elements.Dictionary d = new Dictionary() {    {1, "Applianes"},    {2, "Clothing"},    {3, "Toys"},    {4, "Footwear"},    {5, "Accessories"} };Now, let’s say you need to check whether key 5 exists or not. For that, use ContainsKey() method. It returns True if key is found.d.ContainsKey(5);Let us see the complete code.Exampleusing System; using System.Collections.Generic; public class Program {    public static void Main() {       Dictionary d = new Dictionary() {          {1, "Electronics"},          {2, "Clothing"},          {3, "Toys"},       ...

Read More

Subtract minutes from current time using Calendar.add() method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 3K+ 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 decrement the minutes using the calendar.add() method and Calendar.MINUTE constant. Set a negative value since you want to decrease the minutes.calendar.add(Calendar.MINUTE, -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());       // Subtract 15 minutes from current date       calendar.add(Calendar.MINUTE, -15);   ...

Read More
Showing 7891–7900 of 25,433 articles
« Prev 1 788 789 790 791 792 2544 Next »
Advertisements