[text] 7777777777

Viewer

copydownloadembedprintName: 7777777777
  1. import java.util.*;
  2.  
  3. class Main
  4. {
  5.     public static void main(String args[])
  6.     {
  7.         //Fill your code here
  8.            Scanner sc=new Scanner(System.in);
  9.                    int n=sc.nextInt();
  10.                            int r=sc.nextInt();
  11.                                    int c=sc.nextInt();
  12.                                            int grid[][]=new int[n+1][n+1];
  13.                                                    int v=1;
  14.                                                     for(int i=1;i<=n;i++)
  15.                                                             {
  16.                                                                         if(i%2==1)
  17.                                                                                     {
  18.                                                                                                 for(int j=1;j<=n;j++)
  19.                                                                                                             {
  20.                                                                                                                             grid[i][j]=v;
  21.                                                                                                                                             v++;
  22.                                                                                                             }
  23.                                                                                                                         //System.out.println();
  24.                                                                                                                                     }
  25.                                                                                                                                                 else
  26.                                                                                                                                                             {
  27.                                                                                                                                                                     for(int j=n;j>=1;j--)
  28.                                                                                                                                                                                     {
  29.                                                                                                                                                                                                         grid[i][j]=v;
  30.                                                                                                                                                                                                                             v++;
  31.                                                                                                                                                                                                                                              //   System.out.print(grid[i][j]+" ");
  32.                                                                                                                                                                                                                                                              }
  33.                                                                                                                                                                                                                                                                              //System.out.println();
  34.                                                                                                                                                                                                                                                                                          }
  35.                                                                                                                                                                                                                                                                                                  }
  36.                                                                                                                                                                                                                                                                                                   for(int i=1;i<=n;i++)
  37.                                                                                                                                                                                                                                                                                                           {
  38.                                                                                                                                                                                                                                                                                                                       for(int j=1;j<=n;j++)
  39.                                                                                                                                                                                                                                                                                                                                   {
  40.                                                                                                                                                                                                                                                                                                                                                   System.out.print(grid[i][j]+" ");
  41.                                                                                                                                                                                                                                                                                                                                                               }
  42.                                                                                                                                                                                                                                                                                                                                                                           System.out.println();
  43.                                                                                                                                                                                                                                                                                                                                                                                   }
  44.                                                                                                                                                                                                                                                                                                                                                                                           System.out.println(grid[r][c]);
  45.     }
  46. }

Editor

You can edit this paste and save as new:


File Description
  • 7777777777
  • Paste Code
  • 20 May-2024
  • 7.19 Kb
You can Share it: