SlideShare uma empresa Scribd logo
1 de 21
Advanced Programming
Sample Input: Sample Output:
3 6 9
2 5 8
1 4 7
Question 1
Write a Java code to rotate the matrix 90 degrees anticlockwise.
3
3
1 2 3
4 5 6
7 8 9
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int r = in.nextInt();
int c = in.nextInt();
int matrix[][] = new int[r][c];
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
matrix[i][j] = in.nextInt();
}
}
for(int i = r - 1; i >= 0; i--){
for(int j = 0; j <= c-1; j++){
System.out.print(matrix[j][i] + " ");
}
System.out.println();
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sample Input: Sample Output:
1 5 9 2 6 3
Question 2
Write a Java code to print all the upper triangular matrix elements of the
given square matrix.
3
3
1 2 3
4 5 6
7 8 9
import java.util.Scanner;
class Main
{
public static void main(String args[])
{
int i, j;
Scanner sc = new Scanner(System.in);
int r = sc.nextInt();
int c = sc.nextInt();
int[][] matrix = new int[r][c];
for(i = 0; i < r; i++)
{
for(j = 0; j < c; j++)
{
matrix[i][j] = sc.nextInt();
}
}
upper_matrix(r, c, matrix);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static void upper_matrix(int r, int c, int[][] matrix)
{
int i, j, k;
for(k = 0; k < c; k++)
{
for(i = 0, j = k; j < c ; i++, j++)
System.out.print(matrix[i][j]+" ");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sample Input: Sample Output:
No
Question 3
Write a Java code to check whether the given two matrices are identical or
not.
3 3
matrix1[][]
1 2 3
4 5 6
7 8 9
matrix2[][]
1 2 3
4 5 6
7 8 9
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int flag = 0;
int r = in.nextInt();
int c = in.nextInt();
int a[][] = new int[r][c];
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++){
a[i][j] = in.nextInt();
}
}
int b[][] = new int[r][c];
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
b[i][j] = in.nextInt();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
if(a[i][j] != b[i][j])
{
flag = 1;
break;
}
}
}
if(flag == 0)
System.out.print("Yes");
else
System.out.print("No");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Question 4
India has organized a blind folded ball passing game for two players.
They have a special kind of ground where player B can throw the ball in any
four directions (up, down, right, left).
The ground consists of some slant poles on which, when the ball strikes the
ball changes its direction by 90 degrees.
Consider the below field of 2 x 2 where the ball is at location 0,0 and being
thrown to its right. After hitting slant pole "", it will change direction and go
to 1,1.
B 
- -
Question 4
If suppose you have thrown a ball in a direction in which there is no pole
then the ball goes out of the stadium in that direction.
Player B has the ball initially. The objective is to output the minimum steps
in which B can pass the ball to A and also the count of poles the ball has
struck.
If he can never pass the ball to A, then your output should be -1.
If you get multiple minimum steps then output those steps in which the ball
hits minimum no of barriers
Question 4
Input Format:
First line containing the integer K indicating the size of the field
Next two lines each having a pair of integers separated by space giving the
row and column numbers of
the positions of A and B respectively K lines of K integers each, separated
by space, giving the positions of
the barriers in the field - 0 indicating no barrier, 1 indicating a / barrier and 2
indicating a  barrier.
Output Format:
Minimum number of steps required for the ball to reach A
Number of barriers ball on which the ball bounces
Sample Input: Sample Output:
4
3
Question 4
field_size = 4
A's position = 1 3
B's position = 3 3
Field[][]
0 0 0 0
1 1 1 0
2 2 2 2
1 1 1 0
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int K = sc.nextInt();
int a_pos_row = sc.nextInt();
int a_pos_col = sc.nextInt();
int b_pos_row = sc.nextInt();
int b_pos_col = sc.nextInt();
int play_field[][] = new int[K][K];
for(int i = 0; i < K; i++)
{
for(int j = 0; j < K; j++)
{
play_field[i][j] = sc.nextInt();
}
}
int min_step = -1;
int min_barriers = -1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
for(int i = 0; i <= 3; i++)
{
int direction = i;
int curr_row = b_pos_row, curr_col = b_pos_col;
int step = 0, barrier_count = 0;
while(true)
{
if(curr_col < 0 || curr_col >= K || curr_row < 0 ||
curr_row >= K)
{
break;
}
if(curr_row == a_pos_row && curr_col == a_pos_col)
{
if(min_step > step || min_step == -1)
{
min_step = step;
min_barriers = barrier_count;
}
else if (min_step == step && min_barriers >
barrier_count)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
for(int i = 0; i <= 3; i++)
{
min_barriers = barrier_count;
}
break;
}
step++;
if(play_field[curr_row][curr_col] == 1 ||
play_field[curr_row][curr_col] == 2)
{
barrier_count++;
}
switch(direction)
{
case 0:
if(play_field[curr_row][curr_col] == 1)
{
curr_col++;
direction = 2;
}
else if(play_field[curr_row][curr_col] == 2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
curr_col--;
direction = 3;
}
else
{
curr_row--;
}
break;
case 1:
if(play_field[curr_row][curr_col] == 1)
{
curr_col--;
direction = 3;
}
else if(play_field[curr_row][curr_col] == 2)
{
curr_col++;
direction = 2;
}
else
{
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
curr_row++;
}
break;
case 2:
if(play_field[curr_row][curr_col] == 1)
{
curr_row--;
direction = 0;
}
else if(play_field[curr_row][curr_col] == 2)
{
curr_row++;
direction = 1;
}
else
{
curr_col++;
}
break;
case 3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if(play_field[curr_row][curr_col] == 1){
curr_row++;
direction = 1;
}
else if(play_field[curr_row][curr_col] == 2){
curr_row--;
direction = 0;
}
else{
curr_col--;
}break;
}
}
}
if(min_step != -1) {
System.out.println(min_step);
System.out.print(min_barriers);
}
else{
System.out.print("-1");}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
THANK YOU

Mais conteúdo relacionado

Semelhante a WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-2D_Program_1.2.pptx

Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaanwalia Shaan
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paperfntsofttech
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfarchanaemporium
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfkokah57440
 
Demonstrating bully algorithm in java
Demonstrating bully algorithm in javaDemonstrating bully algorithm in java
Demonstrating bully algorithm in javaNagireddy Dwarampudi
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2Ankit Gupta
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Nishan Barot
 
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdfSolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdfannaimobiles
 
Computer science ms
Computer science msComputer science ms
Computer science msB Bhuvanesh
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsSunil Yadav
 

Semelhante a WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-2D_Program_1.2.pptx (19)

Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdf
 
Demonstrating bully algorithm in java
Demonstrating bully algorithm in javaDemonstrating bully algorithm in java
Demonstrating bully algorithm in java
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
Automata fix.pdf
Automata fix.pdfAutomata fix.pdf
Automata fix.pdf
 
Java Program
Java ProgramJava Program
Java Program
 
Java oops features
Java oops featuresJava oops features
Java oops features
 
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdfSolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
 
Computer science ms
Computer science msComputer science ms
Computer science ms
 
CS.3.Arrays.pdf
CS.3.Arrays.pdfCS.3.Arrays.pdf
CS.3.Arrays.pdf
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 
Insertion Sort Code
Insertion Sort CodeInsertion Sort Code
Insertion Sort Code
 
Doc 20180130-wa0006
Doc 20180130-wa0006Doc 20180130-wa0006
Doc 20180130-wa0006
 

Mais de MaruMengesha

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...MaruMengesha
 
Chemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text bookChemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text bookMaruMengesha
 
eco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation Assignmenteco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation AssignmentMaruMengesha
 
G12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text bookG12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text bookMaruMengesha
 

Mais de MaruMengesha (10)

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
 
Chemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text bookChemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text book
 
eco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation Assignmenteco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation Assignment
 
G12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text bookG12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text book
 

Último

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 

Último (20)

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-2D_Program_1.2.pptx

  • 1.
  • 3. Sample Input: Sample Output: 3 6 9 2 5 8 1 4 7 Question 1 Write a Java code to rotate the matrix 90 degrees anticlockwise. 3 3 1 2 3 4 5 6 7 8 9
  • 4. import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner in = new Scanner(System.in); int r = in.nextInt(); int c = in.nextInt(); int matrix[][] = new int[r][c]; for(int i = 0; i < r; i++){ for(int j = 0; j < c; j++){ matrix[i][j] = in.nextInt(); } } for(int i = r - 1; i >= 0; i--){ for(int j = 0; j <= c-1; j++){ System.out.print(matrix[j][i] + " "); } System.out.println(); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 5. Sample Input: Sample Output: 1 5 9 2 6 3 Question 2 Write a Java code to print all the upper triangular matrix elements of the given square matrix. 3 3 1 2 3 4 5 6 7 8 9
  • 6. import java.util.Scanner; class Main { public static void main(String args[]) { int i, j; Scanner sc = new Scanner(System.in); int r = sc.nextInt(); int c = sc.nextInt(); int[][] matrix = new int[r][c]; for(i = 0; i < r; i++) { for(j = 0; j < c; j++) { matrix[i][j] = sc.nextInt(); } } upper_matrix(r, c, matrix); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 7. public static void upper_matrix(int r, int c, int[][] matrix) { int i, j, k; for(k = 0; k < c; k++) { for(i = 0, j = k; j < c ; i++, j++) System.out.print(matrix[i][j]+" "); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 8. Sample Input: Sample Output: No Question 3 Write a Java code to check whether the given two matrices are identical or not. 3 3 matrix1[][] 1 2 3 4 5 6 7 8 9 matrix2[][] 1 2 3 4 5 6 7 8 9
  • 9. import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner in = new Scanner(System.in); int flag = 0; int r = in.nextInt(); int c = in.nextInt(); int a[][] = new int[r][c]; for(int i = 0; i < r; i++) { for(int j = 0; j < c; j++){ a[i][j] = in.nextInt(); } } int b[][] = new int[r][c]; for(int i = 0; i < r; i++){ for(int j = 0; j < c; j++){ b[i][j] = in.nextInt(); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 10. for(int i = 0; i < r; i++) { for(int j = 0; j < c; j++) { if(a[i][j] != b[i][j]) { flag = 1; break; } } } if(flag == 0) System.out.print("Yes"); else System.out.print("No"); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 11. Question 4 India has organized a blind folded ball passing game for two players. They have a special kind of ground where player B can throw the ball in any four directions (up, down, right, left). The ground consists of some slant poles on which, when the ball strikes the ball changes its direction by 90 degrees. Consider the below field of 2 x 2 where the ball is at location 0,0 and being thrown to its right. After hitting slant pole "", it will change direction and go to 1,1. B - -
  • 12. Question 4 If suppose you have thrown a ball in a direction in which there is no pole then the ball goes out of the stadium in that direction. Player B has the ball initially. The objective is to output the minimum steps in which B can pass the ball to A and also the count of poles the ball has struck. If he can never pass the ball to A, then your output should be -1. If you get multiple minimum steps then output those steps in which the ball hits minimum no of barriers
  • 13. Question 4 Input Format: First line containing the integer K indicating the size of the field Next two lines each having a pair of integers separated by space giving the row and column numbers of the positions of A and B respectively K lines of K integers each, separated by space, giving the positions of the barriers in the field - 0 indicating no barrier, 1 indicating a / barrier and 2 indicating a barrier. Output Format: Minimum number of steps required for the ball to reach A Number of barriers ball on which the ball bounces
  • 14. Sample Input: Sample Output: 4 3 Question 4 field_size = 4 A's position = 1 3 B's position = 3 3 Field[][] 0 0 0 0 1 1 1 0 2 2 2 2 1 1 1 0
  • 15. import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int K = sc.nextInt(); int a_pos_row = sc.nextInt(); int a_pos_col = sc.nextInt(); int b_pos_row = sc.nextInt(); int b_pos_col = sc.nextInt(); int play_field[][] = new int[K][K]; for(int i = 0; i < K; i++) { for(int j = 0; j < K; j++) { play_field[i][j] = sc.nextInt(); } } int min_step = -1; int min_barriers = -1; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 16. for(int i = 0; i <= 3; i++) { int direction = i; int curr_row = b_pos_row, curr_col = b_pos_col; int step = 0, barrier_count = 0; while(true) { if(curr_col < 0 || curr_col >= K || curr_row < 0 || curr_row >= K) { break; } if(curr_row == a_pos_row && curr_col == a_pos_col) { if(min_step > step || min_step == -1) { min_step = step; min_barriers = barrier_count; } else if (min_step == step && min_barriers > barrier_count) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 17. for(int i = 0; i <= 3; i++) { min_barriers = barrier_count; } break; } step++; if(play_field[curr_row][curr_col] == 1 || play_field[curr_row][curr_col] == 2) { barrier_count++; } switch(direction) { case 0: if(play_field[curr_row][curr_col] == 1) { curr_col++; direction = 2; } else if(play_field[curr_row][curr_col] == 2) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 18. curr_col--; direction = 3; } else { curr_row--; } break; case 1: if(play_field[curr_row][curr_col] == 1) { curr_col--; direction = 3; } else if(play_field[curr_row][curr_col] == 2) { curr_col++; direction = 2; } else { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 19. curr_row++; } break; case 2: if(play_field[curr_row][curr_col] == 1) { curr_row--; direction = 0; } else if(play_field[curr_row][curr_col] == 2) { curr_row++; direction = 1; } else { curr_col++; } break; case 3: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 20. if(play_field[curr_row][curr_col] == 1){ curr_row++; direction = 1; } else if(play_field[curr_row][curr_col] == 2){ curr_row--; direction = 0; } else{ curr_col--; }break; } } } if(min_step != -1) { System.out.println(min_step); System.out.print(min_barriers); } else{ System.out.print("-1");} } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Notas do Editor

  1. 1st slide (Mandatory)
  2. Question (Programming) (Add slide 20)
  3. Question (Programming) (Add slide 20)
  4. Question (Programming) (Add slide 20)
  5. Output: True false Description: Here in the first output statement, the '*' takes the preceding value 'a' as its value and compares with the given string. Therefore, it gives the output as true. Whereas in the second case, '*' takes its value as 'a' and gets compared with 'k' in the given string. Hence, it gives the result as false.
  6. Thank you slide