karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 32 of 143

Handling missing keys in Python dictionaries

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

In Python there is one container called the Dictionary. In the dictionaries, we can map keys to its value. Using dictionary the values can be accessed in constant time. But when the given keys are not present, it may occur some errors. In this section we will see how to handle these kind of errors. If we are trying to access missing keys, it may return errors like this. Example code country_dict = {'India' : 'IN', 'Australia' : 'AU', 'Brazil' : 'BR'} print(country_dict['Australia']) print(country_dict['Canada']) # This will return error Output AU --------------------------------------------------------------------------- KeyErrorTraceback (most recent call last) ...

Read More

Java Program to Match Dates

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

Firstly, we have considered the following two dates.SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = s.parse("2018-10-15"); Date d2 = s.parse("2018-11-10");Now, use the compareTo() method to compare both the dates. The results are displayed on the basis of the return value.if (d1.compareTo(d2) > 0) {    System.out.println("Date1 is after Date2!");    } else if (d1.compareTo(d2) < 0) {       System.out.println("Date1 is before Date2!");    } else if (d1.compareTo(d2) == 0) {       System.out.println("Date1 is equal to Date2!");    } else {       System.out.println("How to get here?"); }Exampleimport java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Demo ...

Read More

Implicit conversion from 32-bit unsigned integer (UInt) to Decimal in C#

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

Implicit conversion of a 32-bit unsigned integer (UInt) to a Decimal requires you to first declare a UInt.uint val = 342741539;Now to convert it to decimal, just assign the value.decimal dec; // implicit dec = val;Exampleusing System; public class Demo {    public static void Main() {       uint val = 342741539;       decimal dec;       // implicit       dec = val;       Console.WriteLine("Decimal = "+dec);    } }OutputDecimal = 342741539

Read More

Display three-digit day of the year in Java

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

Use the ‘j’ date conversion character to display three-digit day of the year.System.out.printf("Three-digit Day of the Year: %tj/%Tj", d, d);Above, d is a date object −Date d = new Date();The following is an example −Exampleimport java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; public class Demo {    public static void main(String[] args) throws Exception {       Date d = new Date();       DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");       String format = dateFormat.format(d);       System.out.println("Current date and time = " + format);       System.out.printf("Four-digit Year = %TY", d);       ...

Read More

Convert string of time to time object in Java

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

Here is our string.String strTime = "20:15:40";Now, use the DateFormat to set the format for date.DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");Parse the string of time to time object.Date d = dateFormat.parse(strTime);The following is the complete example.Exampleimport java.text.DateFormat; import java.util.Date; import java.text.SimpleDateFormat; public class Demo {     public static void main(String[] args) throws Exception {        String strTime = "20:15:40";        DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");        Date d = dateFormat.parse(strTime);        System.out.println("Resultant Date and Time = " + d);     } }OutputResultant Date and Time = Thu Jan 01 20:15:40 UTC 1970

Read More

C# Program to search for a string in an array of strings

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

Use Linq Contains() method to search for as specific string in an array of strings.string[] arr = { "Bag", "Pen", "Pencil"};Now, add the string in a string variable i.e. the string you want to search.string str = "Pen";Use the Contains() method to search the above string.arr.AsQueryable().Contains(str);Let us see the entire example.Exampleusing System; using System.Linq; using System.Collections.Generic; class Demo {    static void Main() {       string[] arr = { "Bag", "Pen", "Pencil"};       string str = "Pen";       bool res = arr.AsQueryable().Contains(str);       Console.WriteLine("String Pen is in the array? "+res);    } ...

Read More

Return type of getchar(), fgetc() and getc() in C

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

Details about getchar(), fgetc() and getc() functions in C programming are given as follows −The getchar() functionThe getchar() function obtains a character from stdin. It returns the character that was read in the form of an integer or EOF if an error occurs.A program that demonstrates this is as follows −Example#include int main (){    int i;    printf("Enter a character: ");    i = getchar();    printf("The character entered is: ");    putchar(i);    return(0); }OutputThe output of the above program is as follows −Enter a character: G The character entered is: GNow let ...

Read More

C# OverflowException

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

OverflowException is thrown when the parameter value is out of integer ranges.Let us see an example.When we set a value to int.Parse() method that is out of integer range, then OverflowException is thrown as shown below −Exampleusing System; class Demo {    static void Main() {       string str = "757657657657657";       int res = int.Parse(str);    } }OutputThe following error is thrown when the above program is compiled since we have passed a value that is out of integer (Int32) range.Unhandled Exception: System.OverflowException: Value was either too large or too small for an Int32.

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

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
Showing 311–320 of 1,421 articles
« Prev 1 30 31 32 33 34 143 Next »
Advertisements