From 08bbca303ef45cfb434c2b44ee5811c7edaafad0 Mon Sep 17 00:00:00 2001 From: Dhiraj Kumar Gupta <59963827+dhirajgupta12@users.noreply.github.com> Date: Fri, 22 Oct 2021 19:03:34 +0530 Subject: [PATCH] Added solution of Array Question The State Of Wakanda. The historic state of Wakanda has various monuments and souvenirs which are visited by many travelers every day. The guides follow a prescribed route of visiting the monuments which improves their understanding of the relevance of each monument. The route of the monument is fixed and expressed in a 2-d matrix where the travelers visit the prescribed next monument. For example 1 2 3 4 5 6 7 8 9 is the prescribed route and the visitors travels this path: 1->2->3->4->5->6->7->8->9 However, a certain visitor decides to travel a different path as follows: 1. He first travels southwards till no further south places are available. 2. He then moves only 1 place eastwards. 3. He starts to move again towards north till any further north moves are available. This continues till all the places are covered. For example, the monuments are named as follows: 1 2 3 4 5 6 7 8 9 Path followed by traveler: 1->4->7->8->5->2->3->6->9 You are required to print the path that this traveler follows to visit all places. 1. You will be given a number n, representing the number of rows. 2. You will be given a number m, representing the number of columns. 3. You will be given n*m numbers, representing elements of 2d arrays. Note - Please check the output format for details. --- TheStateOfWakanda1.java | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 TheStateOfWakanda1.java diff --git a/TheStateOfWakanda1.java b/TheStateOfWakanda1.java new file mode 100644 index 0000000..edb0749 --- /dev/null +++ b/TheStateOfWakanda1.java @@ -0,0 +1,55 @@ +import java.util.Scanner; + +public class TheStateOfWakanda1 { + + public static void Display(int [][] a) + { + for (int i = 0; i < a.length; i++) { + for (int j = 0; j < a[0].length; j++) { + + System.out.print(a[i][j]+" "); + + } + System.out.println(); + } + } + + public static void main(String[] args) { + + Scanner scn = new Scanner(System.in); + + int row = scn.nextInt(); + int coloumn = scn.nextInt(); + + int [][] twodArray = new int[row][coloumn]; + + for (int i = 0; i < twodArray.length; i++) { + for (int j = 0; j < twodArray[0].length; j++) { + + twodArray[i][j] = scn.nextInt(); + + } + } + + for(int j = 0; j=0; i--) + { + System.out.println(twodArray[i][j]); + } + } + } + + + } + +}