Skip to content

Instantly share code, notes, and snippets.

View john-nash-rs's full-sized avatar
🎯
Focusing

Harsh Vardhan john-nash-rs

🎯
Focusing
View GitHub Profile
package main
import "fmt"
type Student struct {
Name string
Address string
Class string
}
func main() {
students := make(map[int]string)
students[0] = "Harsh"
students[1] = "Yash"
fmt.Println(students)
delete(students, 1)
fmt.Println(students)
students[1] = "Jain"
for roll, name := range students{
fmt.Printf("Roll number of %s is %d \n",name, roll)
func main() {
cricketer := []string{1:"Sachin", 2:"Ponting", 3: "Waugh", 4: "Zaheer", 5: "Waqar", 6:"Lee"}
batsman := cricketer[1:4]
bowler := cricketer[4:7]
fmt.Println(batsman)
fmt.Println(bowler)
cricketer = append(cricketer, "McGrath")
fmt.Println(bowler)
fmt.Println(cricketer)
func main() {
var a [3]int = [3]int{1,2,3}
fmt.Println("Element at index is",a[1])
fmt.Println("Length of array is",len(a))
for i, v := range(a){
fmt.Printf("Index is %d, and value is %d \n",i,v)
}
q := [...]int{1, 2, 3}
package main
import "fmt"
func main(){
var x complex128 = complex(1, 2)
var y complex128 = complex(3, 4)
fmt.Println(x*y)
fmt.Println(real(x*y))
fmt.Println(imag(x*y))
func main(){
f := 100
x := &f
fmt.Printf(" value of f is %d and the address where f is stored %x \n", f, x);
*x = *x * 2
fmt.Printf(" value of f is %d and the address where f is stored %x \n", f, x);
}
package main
import "fmt"
const boilingF = 212.0
func main(){
var f = boilingF
var c = (f - 32) * 5/9;
fmt.Printf(" boiling point in Centigrade %g and in Fahrenheit %g \n", c, f);
package com.company;
import java.util.concurrent.*;
public class Main {
/**
* To book a parking, we need customer details and parking details.
* And we don't need any booking return object for the client, in other word,
* we can make booking process async/
private static void demoCancel() throws InterruptedException, ExecutionException {
CompletableFuture<String> completableFutureFirst = CompletableFuture.supplyAsync(() -> {
System.out.println("Task Running inside completable Future");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "result";
});
private static void demoCompleteExceptionally() throws InterruptedException, ExecutionException {
CompletableFuture<String> completableFutureFirst = CompletableFuture.supplyAsync(() -> {
System.out.println("Task Running inside completable Future");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "oops";
});