Explain Try-Catch-Finally Block in PowerShell

Chirag Nagrekar
Updated on 06-Jun-2020 13:07:37

8K+ Views

Try/Catch block in PowerShell is to handle the errors which are produced in the script. To be specific, the errors should be terminating errors. The Finally block in the PowerShell is not mandatory to write each time along with Try/Catch but it will be executed regardless the error occurs or not.So when you use the Try block, the Catch block is mandatory but not Finally block.Try/Catch block with Terminating error − Below is the example of Terminating error without finally block.Exampletry{    This is not allowed    "This is Allowed" } catch{    Write-Host "Error occured" -BackgroundColor DarkRed }OutputPS C:\WINDOWS\system32> ... Read More

Count Divisors of N with Common Digits in Java

Sunidhi Bansal
Updated on 06-Jun-2020 12:18:23

249 Views

We are given with a number let’s say, num and the task is to calculate the divisor of a given number thereby count the divisors of num that have at least one digit common with n.Input − num = 24Output − Count is 4Explanation − we will perform the following steps −Firstly, calculate the divisors of a given numberDivisors of 24 are − 1, 2, 3, 4, 6, 8, 12, 24Secondly, check which divisor have at least one digit that matches with the digits of a number2, 4, 12, 24 are the divisors that contain the digit that matches with ... Read More

Count Natural Numbers Whose All Permutations are Greater in C++

Sunidhi Bansal
Updated on 06-Jun-2020 12:11:50

498 Views

We are given a natural number let’s say, num and the task is to calculate the count of all those natural numbers whose all permutations are greater than that number.We are working with the following conditions −The data should be natural numbers onlyAll the possible permutations or arrangement of a natural number should be equal or greater than the given number. For example, the number is 20Consider all the numbers till 20 starting from 1 i.e. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20Now check those numbers whose arrangement or permutation is equaled or greater than the given number i.e. 20. Numbers are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11=11, 12

Count Number of Animals in a Zoo from Given Heads and Legs in C++

Sunidhi Bansal
Updated on 06-Jun-2020 12:04:31

1K+ Views

We are given a total number of heads and legs in a zoo and the task is to calculate the total number of animals there in the zoo with the given data. In the below program we are considering animals to be deer and peacocks.Input −heads = 60 legs = 200Output −Count of deers are: 40 Count of peacocks are: 20Explanation −let total number of deers to be : x Let total number of peacocks to be : y As head can be only one so first equation will be : x + y = 60 And deers have 4 ... Read More

Count Frequency of K in a Matrix in C++

Sunidhi Bansal
Updated on 06-Jun-2020 12:00:30

328 Views

We are given a matrix of integer values and the task is to calculate the count of the frequency of a given integer variable let’s say, k in the matrix. The size of a matrix can depend upon the size the user wants and in the below program we are taking it to be 4X4. Matrix will be formed on the given condition i.e matrix(i, j) will be i+j. The index value of the first data in a matrix will be 0 and 0 i.e. matrix[0][0] = 0.Input − int size = 4, k = 4Output − count of 4 ... Read More

Count N-Digit Numbers Not Having a Particular Digit in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:56:53

297 Views

We are given a number let’s say, num and a total number of digits stored in an integer type variable let’s say, digi and the task is to calculate the count of those n digits numbers that can be formed where the given digit is not there.Input − n = 2, digit = 2Output − count is 153Explanation − count of all two digit numbers(n) not having digit 2 is 153 as 10, 11, 13, 14, 15, 16, 17, 18, 19, 30, 31, 33, 34, ......., etc.Input − n = 3, digit = 3Output − count is 2187Explanation − count ... Read More

Count Digits in Given Number N Which Divide N in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:53:47

2K+ Views

We are given a number let’s say, N and the task is to find the count of those digits in a number that divides the number N.Points to be rememberIf the digit is 0 then it should be ignored which means count will not be increased for 0.If a digit is appearing twice and it divides the number, then the count will depend upon the digit occurrence. For example, we are given a number 2240 and in this number every digit except the 0 will divide the number and 2 is occurring twice then the count will be 2 for ... Read More

Count N-Digit Numbers Divisible by Given Number in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:51:27

449 Views

We are given the two elements let’s say, d and num, the task is to find the d digit numbers which are divisible by num.In simple words let us suppose we have given an input 2 in d, so we will first find all the 2-digit numbers i.e. from 10-99 and then find all the numbers which are divisible by num.Let us understand more of this with the help of examples −Input − digit = 2, num= 12Output − Count of n digit numbers divisible by given number: 8Explanation − The 2-digit numbers divisible by 12 are 12, 24, 36, ... Read More

Count Entries Equal to X in a Special Matrix in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:49:25

395 Views

Given a square matrix, mat[][] let the elements of the matrix me mat[i][j] = i*j, the task is to count the number of elements in the matrix is equal to x.Matrix is like a 2d array in which numbers or elements are represented as rows and columns.So, let's understand the solution of the problem with the help of examples −Input −matrix[row][col] = {    {1, 2, 3},    {3, 4, 3},    {3, 4, 5}}; x = 3Output −Count of entries equal to x in a special matrix: 4Input −matrix[row][col] = {    {10, 20, 30},    {30, 40, 30}, ... Read More

Maximum Area of Rectangle with Given Perimeter in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:44:04

418 Views

Given a perimeter of a rectangle, the task is to find the maximum area of the rectangle with that given perimeter.A rectangle is a type of parallelogram whose opposite sides are equal and parallel.The perimeter of a rectangle is the sum of all sides of a rectangle; we can also say perimeter is the total distance of the outside of the rectangle.The formula to find the perimeter of a rectangle is − Length + Breadth + Length + Breadth or 2(Length + Breadth)Whereas the area of a rectangle is the size of the rectangular object. The formula for finding the ... Read More

Advertisements