-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaddlePoint.java
More file actions
75 lines (64 loc) · 2.63 KB
/
Copy pathSaddlePoint.java
File metadata and controls
75 lines (64 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.*;
public class SaddlePoint//start of class
{
public static void main (String args[]) {//start of main method
System.out.println("Enter the size ");
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();//obtaining input from user
int arr[][] = new int[size][size];//initialising 2-D array
System.out.println("Enter the data");
for(int i=0;i<size;i++) {//starting a for loop
for (int j=0;j<size;j++) {//starting a nested for loop
arr[i][j] = sc.nextInt();//obtaining input for filling the array
}//ending the nested for loop
}//ending the for loop
int min,max,x;
int flag=0;
for(int i =0; i<size;i++) {//starting a for loop
min = arr[i][0];
x=0;
for(int j=0;j<size;j++) {//starting a nested for loop
if(arr[i][j]<min){//finding smallest value in row
min = arr[i][j];
x=j;
}
}//ending the nested for loop
max=arr[0][x];
for(int k=0;k<size;k++) {//starting a nested for loop
if(arr[k][x]>max){//finding greatest value in column
max=arr[k][x];
}
}//ending nested for loop
if (max==min) {//result when we have a saddlepoint
flag = 1;
System.out.println("Saddle is "+max);
}
if(flag==0) {//result when saddlepoint is not there
System.out.println("no point");
}
}
}//end of main method
}//end of class
/* Variable Description Table
* Variable Type Description
* size int to store the size of the array
* arr[][] int an array to store integers
* i int used in for loop
* j int used in for loop
* min int findsthe row number of the smallest value
* max int finds the column with the greaatest value
* x int points to the row with smallest value
* flag int confirms if there is a saddlepoint
* k int used in for loop
*/
/*
👋 Hi, I’m @aarushinair — Aarushi Nair (she/her)
🎓 CS Engineer | AI Researcher | Software Engineer | DEI Professional
💡 Interests: AI/ML/DL, Responsible Tech, Innovative Technologies, Ethics in AI
🌍 Advocate for Women in Tech | Community & Events Manager @AnitaB.org India
🎙️ Speaker | Content Creator | STEM Mentor
📫 Let’s connect: https://www.linkedin.com/in/aarushinair/
📹 YouTube: Code with Aarushi → https://www.youtube.com/channel/UCKj5T1ELHCmkGKujkpqtl7Q
🐦 Twitter/X: https://x.com/aarushinair_
📁 Portfolio, projects & talks: https://github.com/aarushinair
*/