Samual Sam has Published 2492 Articles

Java Program to locate a character in a string

Samual Sam

Samual Sam

Updated on 21-Jun-2024 11:27:10

13K+ Views

To locate a character in a string, use the indexOf() method.Let’s say the following is our string.String str = "testdemo";Find a character ‘d’ in a string and get the index.int index = str.indexOf( 'd');Example Live Demopublic class Demo {    public static void main(String []args) {       String str ... Read More

Java Program to swap the case of a String

Samual Sam

Samual Sam

Updated on 18-Jun-2024 18:01:46

12K+ Views

To swap the case of a string, use.toLowerCase() for title case string. toLowerCase() for uppercase stringtoUpperCase() for lowercase stringLoop through what we discussed above for all the characters in the sting.for (int i = 0; i > len; i++) {    c = str.charAt(i);    // title case converted to ... Read More

Java program to find the area of a rectangle

Samual Sam

Samual Sam

Updated on 18-Jun-2024 16:59:45

10K+ Views

Area of a rectangle is the product of its length and breadth. Therefore, to calculate the area of a rectangleGet the length of the rectangle form the user.Get the breadth of the rectangle form the user.Calculate their product.Print the product.ExampleBelow is an example to find the area of a rectangle ... Read More

Java Program to fill an array of characters from user input

Samual Sam

Samual Sam

Updated on 18-Jun-2024 16:45:18

14K+ Views

For user input, use the Scanner class with System.in. After getting the input, convert it to character array −char[] a = s.next().toCharArray();Now, display it until the length of the character array i.e. number of elements input by the user −for (int i = 0; i < a.length; i++) {   ... Read More

Java program to find a cube of a given number

Samual Sam

Samual Sam

Updated on 18-Jun-2024 15:48:41

13K+ Views

Cube of a value is simply three times multiplication of the value with self.For example, cube of 2 is (2*2*2) = 8.AlgorithmSteps to find a cube of a given number in Java programming:Take integer variable A.Multiply A three times.Display result as Cube.Exampleimport java.util.Scanner; public class FindingCube {    public ... Read More

Java Program to convert from decimal to binary

Samual Sam

Samual Sam

Updated on 18-Jun-2024 15:20:46

21K+ Views

To convert decimal to binary, Java has a method Integer.toBinaryString(). The method returns a string representation of the integer argument as an unsigned integer in base 2.Let us first declare and initialize an integer variable.int dec = 25;Convert it to binary.String bin = Integer.toBinaryString(dec);Now display the “bin” string, which consists ... Read More

Java program to count occurrences of a word in string

Samual Sam

Samual Sam

Updated on 31-May-2024 16:34:38

11K+ Views

The number of times a word occurs in a string denotes its occurrence count. An example of this is given as follows −String = An apple is red in colour. Word = red The word red occurs 1 time in the above string.A program that demonstrates this is given as ... Read More

Java program to calculate Body Mass Index (BMI)

Samual Sam

Samual Sam

Updated on 31-May-2024 13:04:55

21K+ Views

The Body Mass Index is the body mass in kilogram divided by the square of body height in meters. This is expressed as kg/m^2.A Java program that calculates the Body Mass Index (BMI) is given as follows.Exampleimport java.util.Scanner; public class Example {    public static void main(String args[]) {   ... Read More

Relational Database Management System (RDBMS)

Samual Sam

Samual Sam

Updated on 04-May-2024 19:55:11

15K+ Views

Relational database design (RDD) models’ information and data into a set of tables with rows and columns. Each row of a relation/table represents a record, and each column represents an attribute of data. The Structured Query Language (SQL) is used to manipulate relational databases. The design of a relational database ... Read More

Upskilling: The Sure Shot Career Mantra for 2020

Samual Sam

Samual Sam

Updated on 29-Feb-2024 15:05:00

68 Views

Job trends keep changing every year because of the introduction of new realms of life and business around us. This influence is always felt in the job market. While some professions may become extinct many other new and unheard roles plunge in front of us. As it is well known, ... Read More

Advertisements