karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 39 of 143

Format Calendar with String.format() in Java

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

Firstly, consider an object with date value.Object arrObj[] = { "Date", Calendar.getInstance() };After that, use the String.format() method to format Calendar and display the date.The following is an example.Exampleimport java.util.Calendar; public class Demo {    public static void main(String []args){       Object arrObj[] = { "Date", Calendar.getInstance() };       System.out.println("Formatting Date...");       System.out.println(String.format("%1$s = %2$tY %2$tm %2$te", arrObj));    } }OutputFormatting Date... Date = 2018 11 17

Read More

Make the first letter caps and the rest lowercase in Java

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

The following is an example −Examplepublic class Demo {    public static void main(String[] args) {       String str = "laptop";       System.out.println("Original String = " +str);       // letter one       String strOne = str.substring(0,1).toUpperCase();       // remaining letters       String strTwo = str.substring(1).toLowerCase();       System.out.println("Resultant String = "+strOne + strTwo);    } }OutputOriginal String = laptop Resultant String = Laptop

Read More

Java Program to get full day name

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

To display the full day name, use the SimpleDateFormat(“EEEE”) as shown below −// displaying full-day name f = new SimpleDateFormat("EEEE"); String str = f.format(new Date()); System.out.println("Full Day Name = "+str);Since, we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date.import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;Exampleimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo {    public static void main(String[] args) throws Exception {       // displaying current date and time       Calendar cal = Calendar.getInstance();       SimpleDateFormat simpleformat = new ...

Read More

C# Exponential ("E") Format Specifier

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

The ("E") format specifier converts a number to a string of the following form −"-d.ddd…E+ddd"Or"-d.ddd…e+ddd"Above, "d" is a digit (0-9).Prefix the exponent with an "E" or an "e".Exampleusing System; using System.Globalization; class Demo {    static void Main() {       double d = 3452.7678;       Console.WriteLine(d.ToString("E", CultureInfo.InvariantCulture));       Console.WriteLine(d.ToString("E10", CultureInfo.InvariantCulture));       Console.WriteLine(d.ToString("e", CultureInfo.InvariantCulture));       Console.WriteLine(d.ToString("e10", CultureInfo.InvariantCulture));    } }Output3.452768E+003 3.4527678000E+003 3.452768e+003 3.4527678000e+003

Read More

Java Program to display date and time information in lowercase

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

Firstly, create a Formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();To display complete date and time information use the ‘c’ conversion character. However, to display it in lowercase, use ‘tc’ −f = new Formatter(); System.out.println(f.format("Date and Time (lowercase): %tc", cal));The following is an example −Exampleimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar cal = Calendar.getInstance(); System.out.println("Current date and time: "+cal.getTime()); ...

Read More

C# Percent ("P") Format Specifier

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

The percent ("P") format specifier is used to multiply a number by 100.It converts the number into a string representing a % (percentage).We have the following double type −double val = .975746;If we will set (“P”) format specifier, then the above would result as −97.57 %In the same way, using (“P1”), would only include a single vale after decimal-point.97.6%Exampleusing System; using System.Globalization; class Demo {    static void Main() {       double val = .975746;       Console.WriteLine(val.ToString("P", CultureInfo.InvariantCulture));       Console.WriteLine(val.ToString("P1", CultureInfo.InvariantCulture));       Console.WriteLine(val.ToString("P4", CultureInfo.InvariantCulture));    } }Output97.57 % 97.6 % 97.5746 %

Read More

Parse decimal string to create BigInteger in Java

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

To parse the decimal string to create BigInteger, just set the decimal string in the BigInteger.Here is our BigInteger.BigInteger one; String decStr = "687879"; one = new BigInteger(decStr);Let us see another example −Exampleimport java.math.*; public class Demo {    public static void main(String[] args) {       BigInteger one, two;       String decStr = "4373427";       one = new BigInteger("250");       two = new BigInteger(decStr);       System.out.println("Result (BigInteger) : " +one);       System.out.println("Result (Parsing Decimal String) : " +two);    } }OutputResult (BigInteger) : 250 Result (Parsing Decimal String) : 4373427

Read More

C# Program to get the difference between two dates in seconds

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

Set two dates.DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25);Now calculate the difference between two dates.TimeSpan ts = date2 - date1;Move further and calculate the difference in seconds.ts.TotalSecondsLet us see the complete code.Exampleusing System; using System.Linq; public class Demo {    public static void Main() {       DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20);       DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25);       TimeSpan ts = date2 - date1;       Console.WriteLine("No. of Seconds (Difference) = {0}", ts.TotalSeconds);    } }OutputNo. of Seconds (Difference) = 10745

Read More

Java Program to display previous day from GregorianCalender

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

For GregorianCalendar class, import the following package.import java.util.GregorianCalendar;Create an object.GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();Now, use the following field and add() method with a negative one (-1) to display the previous day.cal.add((GregorianCalendar.DATE), -1)Exampleimport java.util.Calendar; import java.util.GregorianCalendar; public class Demo {    public static void main(String[] a) {       GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();       System.out.println("Current date: " + cal.getTime());       // past date       cal.add((GregorianCalendar.DATE), -1);       System.out.println("Modified date (Previous Day): " + cal.getTime());    } }OutputCurrent date: Mon Nov 19 18:12:53 UTC 2018 Modified date (Previous Day): Sun Nov 18 18:12:53 UTC 2018

Read More

Parse and format to arbitrary radix <= Character.MAX_RADIX in Java

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

Let us set a radix here as.// radix int r = 32;Include the radix here as a BigInteger constructor.BigInteger one = new BigInteger("vv", r);Now get its string representation −String strResult = one.toString(radix);The following is an example −Exampleimport java.math.*; public class Demo { public static void main(String[] args) { // radix int r = 32; BigInteger one = new BigInteger("vv", r); String strResult = one.toString(r); System.out.println(strResult); } }Outputvv

Read More
Showing 381–390 of 1,421 articles
« Prev 1 37 38 39 40 41 143 Next »
Advertisements