Posts

Go Language - Program to Check Krishnamurthy Number

Image
Hello everyone, today we will create a Go program to check if the given number is an Krishnamurthy number or not. Krishnamurthy number is also referred to as a Strong number. A number is said to be Krishnamurthy if the factorial sum of all its digits is equal to that number. For example, Number = 40585   = 4! + 0! + 5! + 8! + 5!   = 1 * 2 * 3 * 4 + 1 + 1 * 2 * 3 * 4 * 5 +  1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 +  1 * 2 * 3 * 4 * 5   = 24 + 1 + 120 +  40320 + 120   =  40585 Example 1: Go program that checks if the given number is a Krishnamurthy number or not. /*Go program to check whether the given * number is a Krishnamurthy number or not. */ package main import "fmt" // Main function func main() { //sample 1 number1 := 40585 KrishnamurthyNumber(number1) //sample 2 number2 := 13789 KrishnamurthyNumber(number2) //sample 3 number3 := 1009 KrishnamurthyNumber(number3) } func KrishnamurthyNumber(number int ) { //initialize sum to 0 sum

Go Language - Program to Check Armstrong Number

Image
Hello everyone, today we will create a Go program to check if the given number is an Armstrong number or not. An Armstrong number is a positive n-digit number that is equal to the sum of the nth powers of their digits.  For example, 2 is an Armstrong number.          2 * 1 = 2 1634 is an Armstrong number.           1 + 1296 + 81 + 256 = 1643 407 is an Armstrong number.           64 +0+ 343 = 407 Some other Armstrong numbers are 1, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 4071634, 8208, 9474, 54748, 92727, 93084, 548834, 1741725, 4210818, 9800817, 9926315, 24678050, 24678051, 88593477, 146511208, 472335975, 534494836. Example 1: Let’s create a Go program that checks if the given number is an Armstrong number or not. /* Go program that checks if the given number is an * Armstrong number or not. */ package main import "fmt" // Main function func main() { IsArmstrong( 371 ) IsArmstrong( 431 ) IsArmstrong( 1 ) IsArmstrong( 1634 ) } // Function to calculate x rai

Spring Boot + Mockito simple application with 100% code coverage

Image
In this article, we will show you a simple  Spring Boot example to demonstrate test methods for Controllers, Service, and Repository, And code coverage analysis using the EclEmma plugin. Technologies used: Spring Boot 2.6.4 Mockito 3.11.2 Maven 3+ EclEmma plugin Junit 5 Java 17 A quick overview of  Spring Boot, Mockito, and EclEmma plugin Spring boot: Spring boot to develop REST web services and microservices. Spring Boot has taken the Spring framework to the next level. It has drastically reduced the configuration and setup time required for spring projects. We can set up a project with almost zero configuration and start building the things that actually matter to your application. Mockito: Mockito is a mocking framework, a JAVA-predicated library that is utilized for efficacious unit testing of JAVA applications. Mockito is utilized to mock interfaces so that a dummy functionality can be integrated into a mock interface that can be utilized in unit testing. EclEmma : EclEm