02/07/2020 Programming in Java - Course
https://onlinecourses.nptel.ac.in/noc20_cs08/progassignment?name=170 1/3
Due on 2020-04-03, 23:59 IST
Java Week 9 : Q4
A program needs to be developed which can mirror reflect any 5 × 5 2D character array into its side-by-side reflection. Write suitable code to achieve this
transformation as shown below:
INPUT: OUTPUT:
OOXOO OOXOO OOXOO OOXOO XXXOO OOXXX OOOOO OOOOO XOABC CBAOX
Note the following points carefully
:
1. Here, instead of X and O any character may be present.
2. The input and output array size must be of dimension 5 × 5 and nothing else.
3. Only side-by-side reflection should be performed i.e. ABC || CBA.
Sample Test Cases
Input Output
Test Case 1
XOOOX OXOXO OOXOO OOOOO XOOOO
XOOOX OXOXO OOXOO OOOOO OOOOX X
NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming in Java (course)
(https://swayam.gov.in)
(https://swayam.gov.in/nc_details/NPTEL)Announcements (announcements)
About the Course (https://swayam.gov.in/nd1_noc20_cs08/preview) Ask a Question (forum) Progress (student/home) Mentor (student/mentor)
Course outline
How does an NPTEL online course work?
Week 0 : Week 1 : Week 2 : Week 3 : Week 4 : Week 5 : Week 6 : Week 7 : Week 8 : Week 9 :
Lecture 41 : Demonstration- XV (unit?
unit=10&lesson=55)
02/07/2020 Programming in Java - Course
https://onlinecourses.nptel.ac.in/noc20_cs08/progassignment?name=170 2/3
Test Case 2
OOOXO OOXOO OXOOO OOXOO OOOXO
OXOOO OOXOO OOOXO OOXOO OXOOO
Test Case 3
OOXOO OOXOO OOXOO OOXOO OOXOO
OOXOO OOXOO OOXOO OOXOO OOXOO
Test Case 4
XOXOO OXOOO OOXOO OOOXO OOXOX
OOXOX OOOXO OOXOO OXOOO XOXOO
The due date for submitting this assignment has passed.
As per our records you have not submitted this assignment.
Sample solutions (Provided by instructor)
Week 10 : Week 11 : Week 12 : DOWNLOAD VIDEOS
Lecture 42 : AWT
Programming-- III (unit?
unit=10&lesson=56) Lecture 43 : Swing—I (unit?
unit=10&lesson=57) Lecture 44 : Swing—II (unit?
unit=10&lesson=58) Lecture 45 : Demonstration- XVI (unit?
unit=10&lesson=59) Quiz :
Assignment 9 (assessment?
name=104) Java Week 9 : Q1
(/noc20_cs08/progassignment?
name=167) Java Week 9 : Q2
(/noc20_cs08/progassignment?
name=168) Java Week 9 : Q3
(/noc20_cs08/progassignment?
name=169) Java Week 9 : Q4
(/noc20_cs08/progassignment?
name=170) Java Week 9 : Q5
(/noc20_cs08/progassignment?
name=171) Feedback For Week 9 (unit?
unit=10&lesson=178)
import java.util.Scanner;
public class Question94{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
// Declaring 5x5 2D char array to store input char original[][]= new char[5][5];
// Declaring 5x5 2D char array to store reflection char reflection[][]= new char[5][5];
// Input 2D Array using Scanner Class for(int line=0;line<5; line++){
String input = sc.nextLine();
char seq[] = input.toCharArray();
if(seq.length==5){
for(int i=0;i<5;i++){
original[line][i]=seq[i];
} } }
// Performing the reflection operation for(int i=0; i<5;i++){
for(int j=0; j<5;j++){
reflection[i][j]=original[i][4-j];
} }
// Output the 2D Reflection Array for(int i=0; i<5;i++){
for(int j=0; j<5;j++){
System.out.print(reflection[i][j]);
}
System.out.println();
}
} // The main() method ends here } // The main class ends here
12 34 56 78 109 1112 1314 1516 1718 1920 2122 2324 2526 2728 2930 3132 3334 3536 37
02/07/2020 Programming in Java - Course
https://onlinecourses.nptel.ac.in/noc20_cs08/progassignment?name=170 3/3
Assignment Solution Books
Live Interactive Session