Author

Calculate the average of array element using Java

Below is a program that calculates the average value of an array using Java. public static void main(String[] args) { int[] arr= new int[]{1,2,3,4,5}; int sum = 0; for(int count=0; count < arr.length ; count++) sum = sum + arr[count]; double average = sum / arr.length; System.out.println("The average value of the array elements is :... » read more

Get the sum of array element using Java

Here is a program in Java that sums up all array element and print out the result to the console. class Main { public static void main(String[] args) { int[] arr = {1,2,3,4,5}; int total = 0; for (int i = 0; i < arr.length; i++) total += arr[i]; System.out.printf("The sum of array elements is:... » read more

Get List of Installed Windows Services using C#

Below is a program that will return all installed Windows Services on a local machine. The program uses the namespace System.ServiceProcess, which can be used by adding the Assemblies System.ServiceProcess.dll static void Main(string[] args) { System.ServiceProcess.ServiceController[] services = System.ServiceProcess.ServiceController.GetServices(); foreach (System.ServiceProcess.ServiceController service in services) { Console.WriteLine(service.ServiceName); } Console.ReadKey(); } Happy Coding! More C# Snippets

Get the square root of a number using Java

Square root can be easily obtained in Java by using the Math.sqrt function. The Math is a class in Java that contains methods that allows you to perform mathematical operations. System.out.println(Math.sqrt(9)); Result 3 More Java Snippets

Create a new Thread Delegate using C#

Below is a code that demonstrates how to create a Thread Delegate, which calls a function that will do some work for you in the background. static void Main(string[] args) { // Creating a thread Delegate System.Threading.Thread _thread = new System.Threading.Thread(new System.Threading.ThreadStart(FuctionDoBackgroundWork)); _thread.Start(); } // Fucntion that the thread delegate Starts public static void FuctionDoBackgroundWork()... » read more

Validate Email Address using PHP

Below is a PHP function that validates an email address and returns the result as a boolean. This function uses the PHP built-in function filter_var and the filter FILTER_VALIDATE_EMAIL <?php //php 7.0.8 function ValidateEmail($email) { $email = 'myEmail@myDomain.com'; $isValid = filter_var($email, FILTER_VALIDATE_EMAIL); if ($isValid) { return true; } else { return false; } } ?> Easy isn’t?... » read more

Get Current Page URL using PHP

A PHP function to return the current page URL. <?php function getCurrentURL() { $CurrentURL = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"]; $CurrentURL .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : ""; $CurrentURL .= $_SERVER["REQUEST_URI"]; return $url; } ?> Happy Coding!!! Related Snippets

Get Image Height and Width using PHP

A snippet to get an image height and width using PHP built-in function getimagesize  and list: <?php list($width, $height) = getimagesize("myImage.png"); echo "Image width is " . $width; echo "<br>"; echo "Image height is " . $height; ?> Happy Coding! Related Snippets

Strip Numbers from a String using JavaScript

A code snippet to take all number off a string using JavaScript <script> var MyString = "Tutorials1P2anel3"; stringOnly = MyString.replace(/[0-9]/g, ''); alert(stringOnly); </script> You can replace the alert with anything else that would fit your coding needs. Related Snippets