Mindblown: a blog about philosophy.

  • Calculate Standard Deviation

    This program calculates the standard deviation of a individual series using arrays. To calculate the standard deviation, calculateSD() function is created. The array containing 10 elements is passed to the function and this function calculates the standard deviation and returns it to the main() function. Example: Program to Calculate Standard Deviation Output In the above program, we’ve used the…

  • Find LCM of two Numbers

    LCM using while Loop and if Statement Output In this program, the two numbers whose LCM is to be found are stored in variables n1 and n2 respectively. Then, we initially set lcm to the largest of the two numbers. This is because, LCM cannot be less than the largest number. Inside the infinite while loop (while(true)), we check if lcm perfectly divides…

  • Check Leap Year

    A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400. Java Program to Check a Leap Year Output In the above example, we are checking if the year 1900 is a leap year or not. Since 1900 is…

  • Roots of a Quadratic Equation

    The standard form of a quadratic equation is: Here, a, b, and c are real numbers and a can’t be equal to 0. We can calculate the root of a quadratic by using the formula: The ± sign indicates that there will be two roots: The term b2-4ac is known as the determinant of a quadratic equation. It specifies the nature of roots. That is, if determinant >…

  • Check Vowel or Consonant

    Check vowel or consonant using if..else statement Output In the above program, ‘i’ is stored in a char variable ch. In Java, you use double quotes (” “) for strings and single quotes (‘ ‘) for characters. Now, to check whether ch is vowel or not, we check if ch is any of: (‘a’, ‘e’, ‘i’, ‘o’, ‘u’). This is done using a simple if..else statement.

  • Check Even or Odd

    Output In the above program, a Scanner object, reader is created to read a number from the user’s keyboard. The entered number is then stored in a variable num. Now, to check whether num is even or odd, we calculate its remainder using % operator and check if it is divisible by 2 or not. For this, we use if…else statement in Java. If num is divisible by 2, we print num is…

  • Convert int type to char

    Java Program to Convert int to char In the above example, we have int type variables num1 and num2. Notice the line, Here, we are using typecasting to covert an int type variable into the char type variable. Note that the int values are treated as ASCII values. Hence, we get P for int value 80 and Q for int value 81. It is because the ASCII value of P and Q are 80 and 81 respectively.

  • Convert int to double

    Convert int to double using Typecasting In the above example, we have int type variables a and b. Notice the line, Here, the int type variable is automatically converted into double. It is because double is a higher data type (data type with larger size) and int is a lower data type (data type with smaller size). Hence, there will be no loss in data while converting…

  • Swap Two Numbers

    Swap two numbers using temporary variable Output: In the above program, two numbers 1.20f and 2.45f which are to be swapped are stored in variables: first and second respectively. The variables are printed before swapping using println() to see the results clearly after swapping is done. First, the value of first is stored in variable temporary (temporary = 1.20f). Then, value of second is stored in first (first = 2.45f). And, finally value…

  • Round a Number

    Round a Number using format Output In the above program, we’ve used the format() method to print the given floating-point number num to 4 decimal places.  The 4 decimal places are given by the format .4f. This means, print only up to 4 places after the dot (decimal places), and f means to print the floating-point number.

Got any book recommendations?