Convert a String to a List of Characters in Java

AmitDiwan
Updated on 26-Sep-2019 12:59:14

777 Views

Let’s say the following is our string −String str = "Website!";Now, convert the above string to a list of characters −Listlist = str.chars().mapToObj(n -> (char)n).collect(Collectors.toList());ExampleFollowing is the program to convert a string to a list of characters in Java − Live Demoimport java.util.*; import java.util.stream.Collectors; public class Demo {    public static void main(String[] args){       String str = "Website!";       System.out.println("String = "+str);       Listlist = str.chars().mapToObj(n -> (char)n).collect(Collectors.toList());       System.out.println("List of Characters = "+list);    } }OutputString = Website! List of Characters = [W, e, b, s, i, t, e, !]Read More

Try, catch, throw and throws in Java

AmitDiwan
Updated on 26-Sep-2019 12:47:03

2K+ Views

Try and catch in JavaA method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception.Following is the syntax for try and catch −try {    // Protected code } catch (ExceptionName e1) {    // Catch block }A catch statement involves declaring the type of exception you are trying to catch. If an exception occurs in protected code, the catch block (or blocks) that follows the try is checked. If the type of exception that occurred is listed in a catch block, the exception ... Read More

Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array

Pavitra
Updated on 26-Sep-2019 12:33:11

209 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an array input of integers, we need to find whether it’s possible to make an integer using all the digits available in these numbers such that it would be divisible by 3.Here we will generate a function that will take two arguments namely the array of integers and the length of the array.The implementation given below works on the concept from the mental mathematics. Here we observe that a number is divisible by 3 if the sum of the digits are divisible ... Read More

Python program to check if the given string is pangram

Pavitra
Updated on 26-Sep-2019 12:24:23

6K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a string input, we need to generate a Python program to check whether that string is Pangram or not.A pangram is a sentence/ series of words which contains every letter in the English Alphabets collection.Now let’s see how we can solve the problemWe will use a loop that checks whether each character present in the input string belongs to the alphabet set or not which we will declare manually .The implementation of the approach above is given by −Example Live Demoimport string def ... Read More

Python program to check if a given string is number Palindrome

Pavitra
Updated on 26-Sep-2019 12:22:39

6K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a string input, we need to create a python function to check whether it is a palindrome or not.A string is referred to be palindrome if the reverse of the string is identical with string.We can do this by two methods −Reversal by slicingComparison via negative indexingHere we will be learning reversal pf string bu the help of slicing.To reverse a string by th method of slicing specify the following statement −Str[ : : -1 ]Where the start and end parameters are ... Read More

Python Program to check if the given array is Monotonic

Pavitra
Updated on 26-Sep-2019 12:17:17

996 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an array input Arr containing n integers. We need to check whether the input array is Monotonic in nature or not.An array is said to be monotonic in nature if it is either continuously increasing or continuously decreasing.Mathematically,An array A is continuously increasing if for all i

Python program to check if a string contains all unique characters

Pavitra
Updated on 26-Sep-2019 12:14:14

425 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a sring input, we need to find whether a string contains all unique characters or not.ApproachWe will create an array of boolean values, where the variable flag at the index i indicates that whether character i in the alphabet is contained in the string or not.The second time we encounter this character we can immediately return false as string characters is no longer unique.We can also return false if the string length exceeds the value of number of unique characters presnt in ... Read More

Python Program to Check Armstrong Number

Pavitra
Updated on 26-Sep-2019 12:11:58

1K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an integer n , we need to check that the given integer is an armstrong number.A positive integer is called an Armstrong number of order n ifabcd... = a^n + b^n + c^n + d^n + …Here we will be discussing the brute-force approach for an armstrong number of 3 digits and hence of order three.To check the armstrong number of order n we need to replace 3 by the corresponding order value in line number 7.Now let’s see the implementation −Example Live ... Read More

Python Program for Sum of squares of first n natural numbers

Pavitra
Updated on 26-Sep-2019 12:04:49

595 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a positive integer N as input . We need to compute the value of 12 + 22 + 32 + ….. + N2.Problem statement:This can be solved by two methodsMultiplication addition arithmeticUsing mathematical formulaApproach 1: Multiplication & Addition ArithmeticHere we run a loop from 1 to n and for each i, 1

HTML KeyboardEvent which Property

AmitDiwan
Updated on 26-Sep-2019 12:00:14

37 Views

The HTML KeyboardEvent which property returns the Unicode character code of the key that fires the onkeypress event, onkeydown event or onkeyup event in an HTML document.SyntaxFollowing is the syntax −event.whichLet us see an example of HTML KeyboardEvent which property −Example Live Demo    body {       color: #000;       height: 100vh;       background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;       text-align: center;    }    input {       border: 2px solid #fff;       padding: 8px;       background: transparent;       width: 310px;   ... Read More

Advertisements