Can someone please help me out with below provided JAVA code????? AS PER THE SAM
ID: 3590683 • Letter: C
Question
Can someone please help me out with below provided JAVA code????? AS PER THE SAMPLE OUTPUT WE AS A USER DO NOT NEED TO ENTER ANY INTEGER, we just need to enter the row and coloumns and the code should give the output!You will read in a two dimensional array of characters from the user. Each value will be either a plus sign ) or a minus sign (). There will be only one plus sign in the input. Your task is to output the row and column of the plus sign. Hint: To read in a single character, you can use the Scanner's next method and then get the first character, as shown here scanner 1n new scanner (system . 1n); string temp 1n . next ( ); char c = temp .charAt.(0); Example If the input is: The output would be: 1,6
Explanation / Answer
SearchPlusSign.java
import java.util.Scanner;
public class SearchPlusSign {
public static void main(String[] args) {
//Creating an char 2-D array of size 10 by 10
char arrays[][] = new char[10][10];
//Declaring variables
int row = 0, col = 0;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Getting the input entered by the user
System.out.println("Enter Input :");
for (int i = 0; i < arrays.length; i++) {
for (int j = 0; j < arrays[0].length; j++) {
arrays[i][j] = sc.next(".").charAt(0);
}
}
//calling the method
String location = checkPlusSign(arrays);
//Displaying the output
System.out.print(" '+' Found at :" + location);
}
//This method will check for the location of the + sign in the char array and return the location
private static String checkPlusSign(char[][] arrays) {
for (int i = 0; i < arrays.length; i++) {
for (int j = 0; j < arrays[0].length; j++) {
if (arrays[i][j] == '+') {
return i + "," + j;
}
}
}
return " NotFound";
}
}
___________________
Output:
Enter Input :
- - - - - - - - - -
- - - - - + - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
'+' Found at :1,5
_____________Could you rate me well.Plz .Thank You