Karthikeya Boyini has Published 2383 Articles

Java Program to calculate distance light travels

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

1K+ Views

To calculate distance light travels, we need to follow the basic formulae to calculate distance.Distance = Speed x TimeHere, the following are the parameters −speed = 186000; days = 365; seconds = days * 24 * 60 * 60;Above, we calculated the time in seconds for an year −days = ... Read More

mail() function in PHP

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

227 Views

The mail() function allows in sending emails directly from a script.Syntaxmail(to, sub, msg, headers, parameters);Parametersto − The receiver / receivers of the emailsub − The subject of the email.msg − The message to be sent.headers − The additional headers, such as From, Cc, and Bcc.parameters − The additional parameter to ... Read More

Negate a BigDecimal value in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

210 Views

Use the negate() method to negate a BigDecimal value in Java. The method returns a BigDecimal whose value is (-this), and whose scale is this.scale().The following is an example −Example Live Demoimport java.math.BigDecimal; public class Demo { public static void main(String[] argv) throws Exception { ... Read More

Formatting Minute in m format in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

236 Views

The “m” format is to format minutes i.e. 1, 2, 3, 4, etc. Here, we will use the following.SimpleDateFormat("m");Let us see an example −// displaying minutes in m format SimpleDateFormat simpleformat = new SimpleDateFormat("m"); String strMinute = simpleformat.format(new Date()); System.out.println("Minutes in m format = "+strMinute);Above, we have used the SimpleDateFormat ... Read More

Truncate BigDecimal value in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

2K+ Views

The truncate BigDecimal value in Java, try the following code.Here, we have taken two BigDecimla values and set the round mode for truncating the decimal values −Example Live Demoimport java.math.BigDecimal; public class Demo { public static void main(String[] argv) throws Exception { ... Read More

Working with BigDecimal values in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

1K+ Views

The java.math.BigDecimal class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.Two types of operations are provided for manipulating the scale of a BigDecimal −scaling/rounding operationsdecimal point motion operationsThe following are some of the constructors of the BigDecimal values −Sr.No.Constructor & Description1BigDecimal(BigInteger val)This constructor is used to ... Read More

Java program to get the minimum of three long values

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

60 Views

Firstly, let us declare and initialize three long values.long val1 = 88799; long val2 = 98567; long val3 = 98768;Now, find the minimum of three long values using the following condition −// checking for maximum if (val2 < val1) { val1 = val2; } if (val3 < ... Read More

DecimalFormat(abc#) in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

82 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers.Let us set DecimalFormat(abc#) first −Format f = new DecimalFormat("'abc'#");Now, we will format a number and display the result in a string using the format() method −String res = f.format(-3968.7878);Since, we have used both Format and DecimalFormat class in Java, ... Read More

Convert Long into String using toString() method of Long class in java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

137 Views

The toString() method gives string representation to a Long. Let’s say we have the following Long object −Long longObj = new Long(70); System.out.println("Long: " + longObj);To convert it to String, the toString() method is used −String myStr = longObj.toString();The following is the complete example −Example Live Demopublic class Demo { ... Read More

Format double with new DecimalFormat("0.#####E0") in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

133 Views

Firstly, set the double values −double d1 = 1.39876; double d2 = 2.39876; double d3 = 0.66920;Now, format the double values with new DecimalFormat("0.#####E0") −System.out.println(new DecimalFormat("0.#####E0").format(d1)); System.out.println(new DecimalFormat("0.#####E0").format(d2)); System.out.println(new DecimalFormat("0.#####E0").format(d3));The following is an example −Example Live Demoimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws ... Read More

Advertisements