Karthikeya Boyini has Published 2386 Articles

Java program to check if string is pangram

karthikeya Boyini

karthikeya Boyini

Updated on 27-Jun-2024 17:51:16

7K+ Views

A pangram is a string that contains all the letters of the English alphabet. An example of a pangram is "The quick brown fox jumps over the lazy dog". Problem Statement Given a string, write a Java program to check whether it is pangram or not.Consider the following example - ... Read More

Java Program to convert boolean to integer

karthikeya Boyini

karthikeya Boyini

Updated on 25-Jun-2024 14:39:45

12K+ Views

To convert boolean to integer, let us first declare a variable of boolean primitive. boolean bool = true; Now, to convert it to integer, let us now take an integer variable and return a value “1” for “true” and “0” for “false”. int val = (bool) ? 1 : 0; ... Read More

Java program to find the Frequency of a character in a given String

karthikeya Boyini

karthikeya Boyini

Updated on 24-Jun-2024 15:42:49

5K+ Views

To find the Frequency of a character in a given String Read a string from the user. Read the character. Create an integer variable initialize it with 0. Compare each character in the given string with the entered character increment the above created integer variable each time a match occurs.Exampleimport java.util.Scanner; public class FrequencyOfACharacter ... Read More

Java program to count the number of consonants in a given sentence

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2024 14:36:09

8K+ Views

To count the number of consonants in a given sentence: Read a sentence from the user. Create a variable (count) initialize it with 0; Compare each character in the sentence with the characters {'a', 'e', 'i', 'o', 'u' } If match doesn't occurs increment the count. Finally print count.ExampleBelow is an example to count ... Read More

Java Program to convert an integer into binary

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2024 13:59:18

9K+ Views

To convert an integer to binary, use the Integer.toBinaryString() method in Java.Let’s say the following is the integer we want to convert.int val = 999;Converting the above integer to binary.Integer.toBinaryString(val)Example Live Demopublic class Demo {     public static void main(String[] args) {        int val = 999;        // integer        System.out.println("Integer: "+val);     ... Read More

Java Program to locate a substring in a string

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2024 18:39:39

14K+ Views

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

Java Program to retrieve the set of all keys and values in HashMap

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2024 17:04:46

13K+ Views

To retrieve the set of keys from HashMap, use the keyset() method. However, for set of values, use the values() method.Create a HashMap −HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));Now, retrieve the keys −Set keys = hm.keySet(); Iterator i = keys.iterator(); while (i.hasNext()) ... Read More

Java program to find maximum of three numbers

karthikeya Boyini

karthikeya Boyini

Updated on 14-Jun-2024 15:42:43

21K+ Views

The maximum among three numbers can be found using an if else statement. A Java program that demonstrates this is given as follows.Example Live Demopublic class Example {    public static void main(String args[]) {       int num1 = 15;       int num2 = -5;     ... Read More

Java Program to access character of a string

karthikeya Boyini

karthikeya Boyini

Updated on 14-Jun-2024 14:44:43

31K+ Views

To access character of a string in Java, use the charAt() method. The position is to be added as the parameter.Let’s say we have the following string −String str = "laptop";Let’s find the character at the 4th position using charAt() method.str.charAt(3));The following is the final example.Example Live Demopublic class Demo { ... Read More

Java Program to count letters in a String

karthikeya Boyini

karthikeya Boyini

Updated on 31-May-2024 16:23:29

15K+ Views

Let’s say we have the following string, that has some letters and numbers.String str = "9as78";Now loop through the length of this string and use the Character.isLetter() method. Within that, use the charAt() method to check for each character/ number in the string.for (int i = 0; i < str.length(); ... Read More

1 2 3 4 5 ... 239 Next
Advertisements