Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Section 1

Create a Main.java file and implement the following function.

From a given array of natural numbers, return the distance between the two closest numbers.

import java.util.*;

public class Main {

// Returns the distance between the two closest numbers.


static int distanceClosestNumbers(int[] numbers) {
// Code here
}

public static void main(String[] args) {


int[] a= {2, 9, 40, 15, 84, 7,83, 35};
System.out.println(distanceClosestNumbers(a));
// Expected result is 1 (the 2 closest numbers are 84 and 83)
}
}

Section 2

Tech Stacks: Java Spring Boot + MySql/MongoDB (Choose one)

Go to Spring Initializr (https://start.spring.io/) for your starter template. Add Spring Web MVC
and any required dependency.

User
1. Create a User object class which has a name, phone number, age, gender and
nationality.
2. Create a controller with a few REST Api as listed below:
○ Create user
○ Get all users
○ Get user by name/id
○ Update user
○ Delete user

Order
1. Create an Order object class which has an id, buyer (user), total and paid at.
2. Create a controller with a few REST Api as listed below:
○ Get all orders
○ Get order by id
○ Create order
○ Update order
○ Delete order

Extra
1. Make a REST Api to get orders by user
2. Make a REST Api to get total orders by user

You may test the API by using any HTTP client (preferably Postman)

How to submit:
Compress a folder with the Main.java file (Section 1) and the Java Spring Boot project (Section
2)

You might also like