Mindblown: a blog about philosophy.

  • Capitalize first character of each word

    Java program to make the first letter of a String capital Output In the example, we have converted the first letter of the string name to upper case. Example 2: Convert every word of a String to uppercase Output Here, we have created a string named message we converted the string into a char array we access every element of…

  • Create random strings

    Java program to generate a random string Output In the above example, we have first created a string containing all the alphabets. Next, we have generated a random index number using the nextInt() method of the Random class. Using the random index number, we have generated the random character from the string alphabet. We then used the StringBuilder class to append…

  • Check if a String is Numeric

    Check if a string is numeric Output In the above program, we have a String named string that contains the string to be checked. We also have a boolean value numeric which stores if the final result is numeric or not. To check if the string contains numbers only, in the try block, we use Double‘s parseDouble() method to convert the string to a Double. If it…

  • Calculate simple interest 

     Calculate Simple Interest in Java Output In the above example, we have used the Scanner class to take principal, rate, and time as input from the user. We then use the formula of simple interest to compute the simple interest.

  • Convert Binary Number to Decimal Number

    Binary numbers are numbers consisting only of 2 digits: 0 and 1. They can be expressed in the base 2 numeral system. For example, Decimal numbers are numbers consisting of 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. They can be expressed in the base 10 numeral system. Here, we will be writing a Java program that will convert a binary number into decimal and vice versa using built-in methods and custom…

  • Display Armstrong Number B/w Two Intervals

    A positive integer is called an Armstrong number of order n if abcd… = an + bn + cn + dn + … In case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example: This program is built on the concept of how to check…

  • Display Prime Numbers Between Two Intervals

    Display Prime Numbers Between two Intervals Output In this program, each number between low and high are tested for prime. The inner for loop checks whether the number is prime or not. The difference between checking a single prime number compared to an interval is, you need to reset the value of flag = false on each…

  • Concatenate Two Arrays

     Concatenate Two Arrays using arraycopy Output In the above program, we’ve two integer arrays array1 and array2. In order to combine (concatenate) two arrays, we find its length stored in aLen and bLen respectively. Then, we create a new integer array result with length aLen + bLen. Now, in order to combine both, we copy each element in both arrays to result by…

  • Largest Element of an Array

    Find the largest element in an array Output In the above program, we store the first element of the array in the variable largest. Then, largest is used to compare other elements in the array. If any number is greater than largest, largest is assigned the number. In this way, the largest number is stored in largest when it is printed.

  • Calculate Average Using Arrays

    Output In the above program, the numArray stores the floating-point values whose average is to be found. Then, to calculate the average, we need to first calculate the sum of all elements in the array. This is done using a for-each loop in Java. Finally, we calculate the average by the formula: In this case, the total count is given…

Got any book recommendations?