In Java Fill only the elements at the top and bottom row wit

In Java Fill only the elements at the top and bottom row with zeroes?

Solution

import java.lang.*;

import java.util.Scanner;

class Fill{

public static void main(String args[])

{ int rows, col;

Scanner s = new Scanner(System.in);

//Let us first take number of rows and col and create a array of this size

System.out.println(\"Please enter number of rows\");

rows= s.nextInt();

System.out.println(\"Please enter number of columns\");

col = s.nextInt();

int[][] values = new int[rows][col];

//Now here the first for loop is to iterate over rows , and we need to fill top and bottom row with zero that means firts and the last row, here first starts with index0 hence loop starts with i=0 and then next it should not go to any other index instead directly jump to last row hence we incremented i to i+(rows-1)

for(i=0;i<rows;i+(rows-1))

{for(j=0;j<col;j++)

{

values[i][j]=0;

}

}

}

}

In Java Fill only the elements at the top and bottom row with zeroes?Solutionimport java.lang.*; import java.util.Scanner; class Fill{ public static void main(S

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site