-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaddlePoint.java
66 lines (60 loc) · 2.56 KB
/
SaddlePoint.java
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
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/ella)
👀 I’m a Computer Science Engineering Student
💞️ I’m looking to collaborate on #java, #python, #R, #applicationdevelopment
🌱 #GirlsWhoCode #WomenInTech #WomenInIT #WomenInSTEM #CyberSecurity #QuantumComputing #BlockChain #AI #ML
📫 How to reach me: https://www.linkedin.com/in/aarushinair/
👩🏫 YouTube Channel - Code with Aarushi : https://www.youtube.com/channel/UCKj5T1ELHCmkGKujkpqtl7Q
🙋 Follow me on Twitter: https://twitter.com/aarushinair_