karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 29 of 143

strcspn() in C

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

The function strcspn() counts the number of characters before first match of characters in both strings. This is declared in “string.h” header file. It returns the number of characters of first string before the occurrence of first matched character.Here is the syntax of strcspn() in C language, size_t strcspn(const char *string1, const char *string2)Here, string1 − The first string which is to be scanned.string2 − The second string which is used to search the matching character in first string.Here is an example of strcspn() in C language, Example#include #include int main() {    char str1[] = "Helloworld!";    char str2[] ...

Read More

C# Linq SelectMany Method

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

Use SelectMany method to collapse elements into a single collection like an error.An example would be to convert string to character array. The following is our string array.string[] str = { "Mobile", "Laptop", "Tablet" };Now, convert to character array.str.SelectMany(item => item.ToCharArray());Exampleusing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       string[] str = { "Mobile", "Laptop", "Tablet" };       var res = str.SelectMany(item => item.ToCharArray());       Console.WriteLine("String converted to character array: ");       foreach (char letter in res) {          Console.Write(letter);       }    } }OutputString converted to character array: MobileLaptopTablet

Read More

How to assign int value to char variable in Java

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

To assign int value to a char variable in Java would consider the ASCII value and display the associated character/ digit.Here, we have a char.char val;Now assign int value to it.val = 77;Now, when you will print the value of “val”, it would display the character associate with the value (ASCII) 77.The following is the complete example.Examplepublic class Demo {    public static void main(String []args) {       char val;       val = 77;       System.out.print("Value: ");       System.out.println(val);    } }OutputValue: M

Read More

Hexadecimal literal of type long in Java

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

Hexadecimal literal of type long is represented as − long hexLong = 0XABL; For Hexadecimal, the 0x or 0X is to be placed in the beginning of a number. Note − Digits 10 to 15 are represented by a to f (A to F) in Hexadecimal Example public class Demo { public static void main(String []args) { long hexLong = 0XABL; System.out.println("Hexadecimal literal of type long: "+hexLong); } } Output Hexadecimal literal of type long:171

Read More

Java Program to return a Date set to the last possible millisecond of the minute

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

Let us first set the calendar object −Calendar calendar = Calendar.getInstance();Use the getMaximum() method in Java to returns the maximum value for the given calendar field. We will use it to set the minute, second and milliseconds.For seconds −calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));For milliseconds −calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));The following is an example that returns a Date set to the last possible millisecond of the minute −Exampleimport java.util.Calendar; import java.util.GregorianCalendar; public class Demo {    public static void main(String[] argv) throws Exception {       Calendar calendar = Calendar.getInstance();       // seconds       calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));       // milliseconds   ...

Read More

Locale-specific formatting in Java

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

For locale-specific formatting, firstly import the following packages.import java.util.Calendar; import java.util.Formatter; import java.util.Locale;Create a Formatter and Calendar object −Formatter f = new Formatter(); Calendar c = Calendar.getInstance();We are formatting for different Locales −f.format(Locale.TAIWAN, "Locale.TAIWAN: %tc", c); f.format(Locale.ITALY, "Locale.ITALY: %tc", c);The following is an example −Exampleimport java.util.Calendar; import java.util.Formatter; import java.util.Locale; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar c = Calendar.getInstance(); f.format(Locale.TAIWAN, "Locale.TAIWAN: %tc", c); ...

Read More

Java program to display Astrological sign or Zodiac sign for given date of birth

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

Each date of birth corresponds to a given Zodiac sign. A table that demonstrates these signs and their corresponding dates is given below −Zodiac SignDateAriesMarch 21 - April 19TaurusApril 20 - May 20GeminiMay 21 - June 20CancerJune 21 - July 22LeoJuly 23 - August 22VirgoAugust 23 - September 22LibraSeptember 23 - October 22ScorpioOctober 23 - November 21SagittariusNovember 22 - December 21CapricornDecember 22 - January 19AquariusJanuary 20 - February 18PiscesFebruary 19 - March 20A program that displays the Astrological sign or Zodiac sign for a given date of birth is given as follows.Examplepublic class Example {    public static void main ...

Read More

C# Single() Method

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

Get only a single element of a sequence using the Single() method.Let’s say we have a string array with only one element.string[] str = { "one" };Now, get the element.str.AsQueryable().Single();Here is our code.Exampleusing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       string[] str = { "one" };       string res = str.AsQueryable().Single();       Console.WriteLine(res);    } }Outputone

Read More

Java Program to validate if a String contains only numbers

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

To validate if a String has only numbers, you can try the following codes. We have used the matches() method in Java here to check for number in a string.Examplepublic class Demo {    public static void main(String []args) {       String str = "978";       System.out.println("Checking for string that has only numbers...");       System.out.println("String: "+str);       if(str.matches("[0-9]+") && str.length() > 2)       System.out.println("String has only numbers!");       else       System.out.println("String consist of characters as well!");    } }OutputChecking for string that has only numbers... String: ...

Read More

Formatter Specifier for Octal and Hexadecimal in Java

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

For Formatter, import the following package −import java.util.Formatter;Now create a Formatter object like this −Formatter f1 = new Formatter(); Formatter f2 = new Formatter(); Formatter f3 = new Formatter();If you want a Format specifier for Octal, use %o −f3.format("Octal values %o %o %o", 15, 55, 78);If you want a Format specifier for Hexadecimal, use %x −f2.format("Hexadecimal values %x %x %x", 24, 98, 110);The following is an example −Exampleimport java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f1 = new Formatter(); Formatter ...

Read More
Showing 281–290 of 1,421 articles
« Prev 1 27 28 29 30 31 143 Next »
Advertisements