Go Arrays - Program to find the duplicate elements of an Array

Go program to find the duplicate numbers in an Array

// Go program to find duplicate numbers in an Array
package main

import "fmt"

// Main function
func main() {

// Let’s define an array first
arr := [10]int{33, 2, 1, 22, 2, 6, 3, 1, 33, 9}

for i := 0; i < len(arr); i++ {
for j := i + 1; j < len(arr); j++ {
if arr[i] == arr[j] {
fmt.Println(arr[j])
}
}
}
}


Output:



Go program to find the duplicate words in an Array

// Go program to find duplicate words in an Array
package main

import "fmt"

// Main function
func main() {

// Let’s define an array first
arr := [10]string{
"Go", "Java", "Javascript",
"Python", "Php", "Kotlin",
"Vue", "C", "Go", "Python",
}

for i := 0; i < len(arr); i++ {
for j := i + 1; j < len(arr); j++ {
if arr[i] == arr[j] {
fmt.Println(arr[j])
}
}
}
}


Output:

Comments

Popular posts from this blog

Spring Boot OpenAI Integration: Step-by-Step Guide

Orchestration-Based Saga Architecture and Spring Boot Microservices Implementation Guide

Spring Boot 3 + Angular 15 + Material - Full Stack CRUD Application Example