Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SearchQuery {
- static int count=0;
- static char[] alpha= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
- static int size;
- static int[] x = { -1, -1, -1, 0, 0, 1, 1, 1 };
- static int[] y = { -1, 0, 1, -1, 1, -1, 0, 1 };
- public static void main(String[] args)
- {
- Scanner input=new Scanner(System.in);
- System.out.print("What is the size of the Array?: ");
- size=input.nextInt();
- char[][] matrix=new char[size][size];
- print2D(matrix,size);
- System.out.println("Enter to query to search: ");
- String query=input.nextLine();
- query=input.nextLine();
- searchHorz(matrix,size,query);
- searchVert(matrix,size,query);
- System.out.println(count);
- }
- public static char[][] print2D(char[][] array,int rows)
- {
- for(int i=0;i<rows;i++)
- {
- for(int j=0;j<rows;j++)
- {
- int random=(int)(Math.random()*26);
- array[i][j]=alpha[random];
- System.out.print(array[i][j]);
- }
- System.out.println();
- }
- return array;
- }
- public static int searchHorz(char[][] array,int rows,String word)
- {
- for(int i=0;i<rows;i++)
- {
- for(int j=0;j<rows;j++)
- {
- if(array[i][j]==word.charAt(0))
- {
- count++;
- }
- }
- }
- return count;
- }
- public static int searchVert(char[][] array,int rows,String word)
- {
- for(int i=0;i<rows;i++)
- {
- for(int j=0;j<rows;j++)
- {
- if(array[j][i]==word.charAt(0))
- {
- count++;
- }
- }
- }
- return count;
- }
- public static int searchDiag(char[][] array,int rows,String word)
- {
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement