Samual Sam has Published 2310 Articles

Convert from String to float in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:48:08

1K+ Views

To convert String to float, use the valueOf() method.Let’s say we have the following string value.String str = "0.8";Converting the string to float.Float floatVal = Float.valueOf(str).floatValue();The following is the complete example.Example Live Demopublic class Demo {    public static void main(String args[]) {       String str = "0.8";   ... Read More

Java Program to compare Two Java float Arrays

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:46:48

202 Views

To compare Java float arrays, use the Arrays.equals() method. The return value is a boolean. Let’s say we have the following float arrays −float[] floatVal1 = new float[] { 3.2f, 5.5f, 5.3f }; float[] floatVal2 = new float[] { 8.3f, 8.8f, 9.2f }; float[] floatVal3 = new float[] { 6.2f, ... Read More

C function to Swap strings

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:44:51

746 Views

The following is an example to swap strings.Example Live Demo#include #include int main() {    char st1[] = "My 1st string";    char st2[] = "My 2nd string";    char swap;    int i = 0;    while(st1[i] != '\0') {       swap = st1[i];       ... Read More

C++ Program to Compute Combinations using Factorials

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:39:33

973 Views

The following is an example to compute combinations using factorials.Example Live Demo#include using namespace std; int fact(int n) {    if (n == 0 || n == 1)    return 1;    else    return n * fact(n - 1); } int main() {    int n, r, result;    coutn;    coutr;    result = fact(n) / (fact(r) * fact(n-r));    cout

Print “Hello World” in C/C++ without using header files

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:36:48

794 Views

Generally, we use header files in C/C++ languages to access the built-in functions like int, char, string functions. The function printf() is also a built-in function which is declared in “stdio.h” header file and it is used to print any kind of data on console.Here is an example to print ... Read More

Determine day of week in month from Gregorian Calendar in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:35:26

319 Views

To work with the GregorianCalendar class, import the following package −import java.util.GregorianCalendar;To get the day of week in month, use the following field −cal.get(Calendar.DAY_OF_WEEK_IN_MONTH)Above, cal is the GregorianCalendar object we created before −GregorianCalendar cal = new GregorianCalendar();The following is an example −Example Live Demoimport java.util.GregorianCalendar; import java.util.Calendar; import java.util.Date; public class ... Read More

Static functions in C

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:34:44

21K+ Views

A static function in C is a function that has a scope that is limited to its object file. This means that the static function is only visible in its object file. A function can be declared as static function by placing the static keyword before the function name.An example ... Read More

Format and Parse Date in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:33:29

318 Views

To format a date in Java, firstly import the following package.import java.text.DateFormat;Now, create DateFormat object.DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat longFormat = DateFormat.getDateInstance(DateFormat.LONG);Use the format() method to format the above dates.System.out.println(shortFormat.format(new Date())); System.out.println(longFormat.format(new Date()));To parse the dates, use the parse() method.Example Live Demoimport java.text.DateFormat; import java.text.ParseException; import java.util.Date; public class Demo { ... Read More

Default values of static variables in C

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:31:52

4K+ Views

When static keyword is used, variable or data members or functions can not be modified again. It is allocated for the lifetime of program. Static functions can be called directly by using class name.Static variables are initialized only once. Compiler persist the variable till the end of the program. Static ... Read More

Return values of printf() and scanf() in C

Samual Sam

Samual Sam

Updated on 26-Jun-2020 08:25:18

12K+ Views

The printf() and scanf() functions are required for output and input respectively in C. Both of these functions are library functions and are defined in the stdio.h header file.Details about the return values of the printf() and scanf() functions are given as follows −The printf() functionThe printf() function is used ... Read More

Advertisements