karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 33 of 143

Set a duration in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 195 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

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

C# Linq ElementAt Method

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

The ElementAt() method in C# to get elements at specified index position.Firstly, set the string array.string[] str = { "Jack", "Pat", "David"};Now, to get the element at a particular index, use the ElementAt() method as shown in the following example −Exampleusing System.IO; using System; using System.Linq; class Program {    static void Main() {       string[] str = { "Jack", "Pat", "David"};       Random r = new Random(DateTime.Now.Second);       // to generate random string       string res = str.AsQueryable().ElementAt(r.Next(0, str.Length));       Console.WriteLine("Random Name = '{0}'", res);    } }OutputRandom Name = 'Jack'

Read More

How to print a variable name in C?

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

The following is an example to print variable name.Example#include #define VariableName(name) #name int main() {    int name;    char ch;    printf("The variable name : %s", VariableName(name));    printf("The variable name : %s", VariableName(ch));    return 0; }OutputThe variable name : name The variable name : chIn the above program, the variable names are printed by defining the method before main()#define VariableName(name) #nameTwo variables of different datatypes are declared. By using the defined function, variable names are printed.int name; char ch; printf("The variable name : %s", VariableName(name)); printf("The variable name : %s", VariableName(ch));

Read More

C# Math.DivRem Method

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

Use the Math.DivRem method to calculate the quotient of two numbers and return the remainder.Firstly, set dividend and divisor.// dividend long dividend = 30; // divisor long divisor = 7;Now, use the DivRem method.long quotient = Math.DivRem(dividend, divisor, out rem);Exampleusing System; using System.Globalization; class Demo {    static void Main() {       // remainder       long rem;       // dividend       long dividend = 98;       // divisor       long divisor = 9;       long quotient = Math.DivRem(dividend, divisor, out rem);       Console.WriteLine("{0} \ {1} = {2} and remainder = {3}", dividend, divisor, quotient, rem);    } }Output98 \ 9 = 10 and remainder = 8

Read More

Copy characters from string into char Array in Java

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

Let’s say we have the following string.String str = "Demo Text!";To copy some part of the above string, use the getChars() method.// copy characters from string into chArray =str.getChars( 0, 5, chArray, 0 );The following is an example to copy characters from string into char Array in Java.Examplepublic class Demo {    public static void main(String[] args) {       String str = "Demo Text!";       char chArray[] = new char[ 5 ];       System.out.println("String: "+str);       // copy characters from string into chArray       str.getChars( 0, 5, chArray, 0 ); ...

Read More

C# Console.WindowWidth Property

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

The WindowWidth property gets or sets the width of the console window.Declare a variable.int width;Now, get the width of the current window.width = Console.WindowWidth;The following is the complete example.Exampleusing System; using System.Numerics; using System.Globalization; class Demo {    static void Main() {       int width;       int height;       width = Console.WindowWidth;       height = Console.WindowHeight;       Console.WriteLine("Current window width = "+width);       Console.WriteLine("Current window height = "+height);    } }OutputCurrent window width = 0 Current window height = 0

Read More

Set Date patterns with SimpleDateFormat in Java

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

The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved) for Date and Time in JavaReference − Oracle JavaLetterDate or Time ComponentPresentationExamplesGEra designatorTextADYYearYear1996; 96YWeek yearYear2009; 09MMonth in yearMonthJuly; Jul; 07WWeek in yearNumber27WWeek in monthNumber2DDay in yearNumber189DDay in monthNumber10FDay of week in monthNumber2EDay name in weekTextTuesday; TueUDay number of week (1 = Monday, ..., 7 = Sunday)Number1AAm/pm markerTextPMHHour in day (0-23)Number0KHour in day (1-24)Number24KHour in am/pm (0-11)Number0hHour in am/pm (1-12)Number12mMinute in hourNumber30sSecond in minuteNumber55SMillisecondNumber978zTime zoneGeneral time zonePacific Standard Time; PST; GMT-08:00ZTime zoneRFC 822 time zone-800XTime zoneThe above pattern letters are combined ...

Read More

Java Program to display date with day name in short format

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

Firstly, set the format with SimpleDateFormat classFormat dateFormat = new SimpleDateFormat("EEE, dd/MM/yyyy");Above, the “EEE” is set to display the name of the day i.e. Monday, Tuesday, Wednesday, etc.Now, to display the date −String res = dateFormat.format(new Date());The following is an example −Exampleimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; public class Demo {    public static void main(String[] argv) throws Exception {       Format dateFormat = new SimpleDateFormat("EEE, dd/MM/yyyy");       String res = dateFormat.format(new Date());       System.out.println("Date = " + res);    } }OutputDate = Thu, 22/11/2018

Read More

C# Linq Last() Method

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

Get the last element from a sequence using the Linq Last() method.The following is our array.int[] val = { 10, 20, 30, 40 };Now, get the last element.val.AsQueryable().Last();Exampleusing System; using System.Collections.Generic; using System.Linq; class Demo {    static void Main() {       int[] val = { 10, 20, 30, 40 };       // getting last element       int last_num = val.AsQueryable().Last();       Console.WriteLine("Last element: "+last_num);    } }OutputLast element: 40

Read More
Showing 321–330 of 1,421 articles
« Prev 1 31 32 33 34 35 143 Next »
Advertisements