Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by karthikeya Boyini
Page 19 of 143
sqrt() function in PHP
The sqrt() function Returns the square root of a number.Syntaxsqrt(num)Parametersnum − The number for which you want to find the square rootReturnThe sqrt() function Returns the square root of the specified number.ExampleOutput4ExampleLet us see another example −Output0.5ExampleLet us see another example −OutputNAN
Read MoreJava Program to return a Date set to the last possible millisecond of the day before midnight
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, hours second and milliseconds.For hour and minute.calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE));For second and milliseconds.// second calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND)); // millisecond 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 day before midnight.Exampleimport java.util.Calendar; import java.util.GregorianCalendar; public class Demo { public static void main(String[] argv) throws Exception { Calendar calendar = Calendar.getInstance(); // hour ...
Read MoreBigInteger.isProbablePrime() method in Java
TheBigInteger.isProbablePrime(int certainty) returns true if this BigInteger is probably prime, false if it's definitely composite. If certainty is ≤ 0, true is returned.Here, the “certainty” parameter is a measure of the uncertainty that the caller is willing to tolerate: if the call returns true the probability that this BigInteger is prime exceeds (1 - 1/2certainty). The execution time of this method is proportional to the value of this parameter.The following is an example −Exampleimport java.math.BigInteger; public class Demo { public static void main(String[] argv) throws Exception { // create 3 BigInteger ...
Read MoreLine Separator in Java
Strings have no newlines. We can form them into two lines by concatenating a newline string. Use System lineSeparator to get a platform-dependent newline string.The following is an example.Examplepublic class Demo { public static void main(String[] args) { String str = "one" + System.lineSeparator() + "two"; System.out.println(str); } }Outputone twoLet us see another example. On Linux based system, the program will work correctly.Examplepublic class Demo { public static void main(String[] args) { String str = System.lineSeparator(); System.out.println((int) str.charAt(0)); } }Output10
Read MoreC# General Date Short Time ("g") Format Specifier
The Generate Date Short Time format specifier is a combination of the short date ("d") and short time ("t") patterns, separated by a space.Set a date using DateTime.DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20);Now, use the (“g”) format specifier.dt.ToString("g", DateTimeFormatInfo.InvariantInfo));Exampleusing System; using System.Globalization; class Demo { static void Main() { DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20); Console.WriteLine(dt.ToString("g", DateTimeFormatInfo.InvariantInfo)); Console.WriteLine(dt.ToString("g", CultureInfo.CreateSpecificCulture("en-us"))); } }Output10/02/2018 07:59 10/2/2018 7:59 AM
Read Moretan() function in PHP
The tan() function returns the tangent of the specified value.Syntaxtan(val)Parametersval − A value in radiansReturnThe tan() function returns the tangent of the specified value val.ExampleOutput01.5574077246549ExampleLet us see another example −Output1ExampleLet us see another example −Output0.54630248984379-0.54630248984379ExampleLet us see another example −Output3.3805150062466-0.64836082745909
Read MoreDisplay the minimum and maximum value of primitive data types in Java
Every data type in Java has a minimum as well as maximum range, for example, for Float.Min = 1.4E-45 Max = 3.4028235E38Let’s say for Float, if the value extends the maximum range displayed above, it leads to Overflow.However, if the value is less than the minimum range displayed above, it leads to Underflow.The following is the Java Program to display the minimum and maximum value of primitive data types.Examplepublic class Demo { public static void main(String[] args) { System.out.println("Integer Datatype values..."); System.out.println("Min = " + Integer.MIN_VALUE); System.out.println("Max = " + ...
Read MoreRemove newline, space and tab characters from a string in Java
To remove newline, space and tab characters from a string, replace them with empty as shown below.replaceAll("[\t ]", "");Above, the new line, tab, and space will get replaced with empty, since we have used replaceAll()The following is the complete example.Examplepublic class Demo { public static void main(String[] args) { String originalStr = "Demo\tText"; System.out.println("Original String with tabs, spaces and newline: "+originalStr); originalStr = originalStr.replaceAll("[\t ]", ""); System.out.println("String after removing tabs, spaces and new line: "+originalStr); } }OutputOriginal String with tabs, spaces and newline: Demo Text String ...
Read MoreDisplay AM/PM time marker with SimpleDateFormat(“a”) in Java
You can display AM/PM time marker easily in Java using SimpleDateFormat(“a”).Firstly, to work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“a”) to display AM/PM marker −Format f = new SimpleDateFormat(”a”);Now, get the marker in a string −String strMarker = f.format(new Date());The following is an example −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(); ...
Read MoreC# Program to get the absolute value of the time
To get the absolute value of time, use the TimesSpan Duration() method.Let’s say the following is our TimeSpan.TimeSpan ts = new TimeSpan(-7, -50, -25);Now to get the absolute value.TimeSpan duration = ts.Duration();Let us see the complete code.Exampleusing System; using System.Linq; public class Demo { public static void Main() { TimeSpan ts = new TimeSpan(-7, -50, -25); TimeSpan duration = ts.Duration(); Console.WriteLine(duration); } }Output07:50:25
Read More