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 Samual Sam
Page 18 of 151
Java Program to convert an int to a boolean specifying the conversion values
To convert int to boolean, let us first take the following int.int one = 1; int two = 1; int three = 0;We have nested if-else statement to display the true or false values. Here, the value “one” is the same as “two” i.e. 1; therefore, the following works −else if (one.equals(two)) { System.out.println(true); }The above display “true” and in this way we converted int to boolean.Let us now see the complete example to learn how to convert int to Boolean.Examplepublic class Demo { public static void main(String[] args) { int one = 1; ...
Read MoreConvert.ToDateTime Method in C#
The Convert.ToDateTime method converts a given value to a DateTime value.The following is my string.string myDateString; myDateString = "09/09/2018";Now, let us convert it using the Convert.ToDateTime() method.DateTime result; result = Convert.ToDateTime(myDateString);Here is the complete example.Exampleusing System; public class Demo { public static void Main() { string myDateString; DateTime result; myDateString = "09/09/2018"; result = Convert.ToDateTime(myDateString); Console.WriteLine("'{0}' converted to {1}", myDateString, result); } }Output'09/09/2018' converted to 9/9/2018 12:00:00 AM
Read MoreCount how many times the substring appears in the larger String in Java
Let’s say we have the following string.String str = "Learning never ends! Learning never stops!";In the above string, we need to find out how many times the substring “Learning” appears.For this, loop until the index is not equal to 1 and calculate.while ((index = str.indexOf(subString, index)) != -1) { subStrCount++; index = index + subString.length(); }The following is an example.Examplepublic class Demo { public static void main(String[] args) { String str = "Learning never ends! Learning never stops!"; System.out.println("String: "+str); int subStrCount = 0; String subString = ...
Read MoreJava Program to display double and single quote in a string
The following are our strings with single and double quote.String str1 = "This is Jack's mobile"; String str2 = ""This is it"!";Above, for single quote, we have to mention it normally like.This is Jack's mobileHowever, for double quotes, use the following and add a slash in the beginning as well as at the end.String str2 = ""This is it"!";The following is an example.Examplepublic class Demo { public static void main(String[] args) { String str1 = "This is Jack's mobile"; String str2 = ""This is it"!"; System.out.println("Displaying Single Quote: "+str1); ...
Read MoreC# Program to invert the order of elements in a sequence
Set a string.char[] ch = { 'd', 'r', 'i', 'v', 'e' }; Console.Write("String = foreach(char arr in ch) Console.Write(arr);Now, use Queryable Reverse() method to invert the order of elements.IQueryable res = ch.AsQueryable().Reverse();Let us see the complete code.Exampleusing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { char[] ch = { 'd', 'r', 'i', 'v', 'e' }; Console.Write("String = "); foreach(char arr in ch) Console.Write(arr); IQueryable res = ch.AsQueryable().Reverse(); Console.Write("Reversed = "); foreach (char c in res) Console.Write(c); } }OutputString = drive Reversed = evird
Read MoreJava Program to split a string with dot
Let’s say the following is our string.String str = "Java is a programming language. James Gosling developed it.";We will now see how to split a string using the split() method. Include the delimiter as the parameter.String[] strSplit = str.split("\.");Above, we have split the string with dot as you can see under the split methods parameter.The following is an example.Examplepublic class Demo { public static void main(String[] args) { String str = "Java is a programming language. James Gosling developed it."; System.out.println("String: "+str); String[] strSplit = str.split("\."); System.out.println("Splitting ...
Read MoreDisplay hour in KK (00-11) format in Java
The “KK” format in Java Date is used to display hour in 00-11.. Use SimpleDateFormat("KK") to get the same format −// displaying hour in KK format SimpleDateFormat simpleformat = new SimpleDateFormat("KK"); String strHour = simpleformat.format(new Date()); System.out.println("Hour in KK format = "+strHour);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;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 ...
Read MoreHow to print % using printf()?
Generally, printf() function is used to print the text along with the values. If you want to print % as a string or text, you will have to use ‘%%’. Neither single % will print anything nor it will show any error or warning.Here is an example to print % in printf() in C language, Example#include int main() { printf("%"); printf("%%"); getchar(); return 0; }Output%There are some other ways to print % in the text message as in the following example, Example#include #include int main() { printf("welcome%"); printf("%%"); printf("%c", '%'); printf("%s", "%"); ...
Read MoreSet Decimal Place of a Big Decimal Value in Java
We have the following BigDecimal value −BigDecimal val1 = new BigDecimal("37578975587.876876989");We have set the decimal place to be −int decPlaces1 = 3;Now, we will use the ROUND_DOWN field to set the rounding mode to round towards zero −// ROUND_DOWN val1 = val1.setScale(decPlaces1, BigDecimal.ROUND_DOWN); String str1 = val1.toString(); System.out.println("Result = "+str1);To set decimal place of a BigDecimal value in Java, try the following code −Exampleimport java.math.BigDecimal; public class Demo { public static void main(String[] argv) throws Exception { int decPlaces1 = 3; int decPlaces2 = 5; ...
Read MoreHow to find minimum between 2 numbers using C#?
Firstly, declare and initialize two numbers.int num1 = 35; int num2 = 55;With that, use if- else to find the minimum number.if (num1 < num2) { minNum = num1; } else { minNum = num2; }Above, we have set the minimum value to the variable minNum and printed it later on.The following is the complete example to find minimum between 2 numbers in C#.Exampleusing System; namespace Demo { class Program { static void Main(string[] args) { int num1 = 50; int num2 = 90; ...
Read More