Question

DESCRIPTION: You will be given a 2-D string array, called matrix. The array has an unknown...

DESCRIPTION:

You will be given a 2-D string array, called matrix. The array has an unknown number of cells filled with data. Your goal is to iterate through the 2-D array and keep a count of how many cells contain the string "Angela".

INPUT:

All input has been handled for you:

  • A filled 2-D string array.

PROCESSING:

  • Determine the number of rows in the array matrix
  • Determine the number of columns in the array matrix
  • Use nested loops to iterate through the 2-D array.
  • Keep track of the number of cells that contain the string "Angela".

OUTPUT:

  • Print the result in the format below.

Sample input/output:

Input array  matrix Output
Angela A B
Angela C Angela
D E Angela
F Angela H

Rows: 4
Columns: 3
Angela: 5

Given code:

import java.util.Scanner;

/**
* @author Angela Siegel
* @date 07/17/2020
*/

public class Question2 {


public static void main(String[] args) {
Scanner in = new Scanner(System.in);
  
int count=0;
String[][] matrix = new String[in.nextInt()][];
in.nextLine();

while (in.hasNext()) {
matrix[count] = in.nextLine().split(" ");
count++;
}

       /*========================
       || Start your work here ||
       =========================*/

  

       /*========================
       || End your work here ||
       =========================*/
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

/**
* @author Angela Siegel
* @date 07/17/2020
*/

public class Question2{


public static void main(String[] args) {
Scanner in = new Scanner(System.in);
  
int count=0;
String[][] matrix = new String[in.nextInt()][];
in.nextLine();

while (in.hasNext()) {
matrix[count] = in.nextLine().split(" ");
count++;

}

/*========================
|| Start your work here ||
=========================*/

int rows = matrix.length;//finding number of rows
int cols = matrix[0].length;//finding number of cols
int a=0;//finding angela count
System.out.println("Input array matrix:");
for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
if(matrix[i][j].equals("Angela"))
a++;//finding count of Angela in matrix
System.out.print(matrix[i][j]+" ");
}
System.out.println();
  
}
//displaying output
  
System.out.print("Output:\nRows: "+rows+"\nColumns: "+cols+"\nAngela: "+a);

/*========================
|| End your work here ||
=========================*/
}
}

Add a comment
Know the answer?
Add Answer to:
DESCRIPTION: You will be given a 2-D string array, called matrix. The array has an unknown...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • In this same program I need to create a new method called “int findItem(String[] shoppingList, String...

    In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...

  • DESCRIPTION: The purpose of this question is offload processing from the main method to a static...

    DESCRIPTION: The purpose of this question is offload processing from the main method to a static helper method. You will be given the main method. Do not alter this code. Your goal is to write a new method called oddOneOut, which will accept a String, and print it in out every other letter. For example, if the String was "abcdefghijk", the oddOneOut method will return "acegik" . METHOD INPUT: A string METHOD PROCESSING: Do not alter the  main method. Complete the...

  • Must be done in Java. Provide the rest of the code with full comments and explanation and with proper indentation. Use...

    Must be done in Java. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. CODE PROVIDED: import java.util.ArrayList; import java.util.Scanner; public class Problem3 {    public static void main( String [] args ) {        Scanner in = new Scanner( System.in );        //PLEASE START YOUR WORK HERE        //**********************************************************                                                  //**********************************************************        // PLEASE END YOUR WORK HERE        System.out.print("END OF OUTPUT");    } } 20 points! PROBLEM 3: EXTENDED FAMILY Complete this...

  • PrintArray vi Create a class called PrintArray. This is the class that contains the main method....

    PrintArray vi Create a class called PrintArray. This is the class that contains the main method. Your program must print each of the elements of the array of ints called aa on a separate line (see examples). The method getArray (included in the starter code) reads integers from input and returns them in an array of ints. Use the following starter code: //for this program Arrays.toString(array) is forbidden import java.util.Scanner; public class PrintArray { static Scanner in = new Scanner(System.in);...

  • Fix this program package chapter8_Test; import java.util.Scanner; public class Chapter8 { public static void main(String[] args)...

    Fix this program package chapter8_Test; import java.util.Scanner; public class Chapter8 { public static void main(String[] args) { int[] matrix = {{1,2},{3,4},{5,6},{7,8}}; int columnChoice; int columnTotal = 0; double columnAverage = 0; Scanner input = new Scanner(System.in); System.out.print("Which column would you like to average (1 or 2)? "); columnChoice = input.nextInt(); for(int row = 0;row < matrix.length;++row) { columnTotal += matrix[row][columnChoice]; } columnAverage = columnTotal / (float) matrix.length; System.out.printf("\nThe average of column %d is %.2f\n", columnAverage, columnAverage); } } This program...

  • package week_3; /** Write a method called countUppercase that takes a String array argument. You can...

    package week_3; /** Write a method called countUppercase that takes a String array argument. You can assume that every element in the array is a one-letter String, for example String[] test = { "a", "B", "c", "D", "e"}; This method will count the number of uppercase letters from the set A through Z in the array, and return that number. So for the example array above, your method will return 2. You will need to use some Java library methods....

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

  • //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args )...

    //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args ) { Scanner in = new Scanner( System.in ); LinkedList teamList = new LinkedList(); final int TEAM_SIZE = Integer.valueOf(in.nextLine()); for (int i=0; i<TEAM_SIZE; i++) { String newTeamMember = in.nextLine(); teamList.append(newTeamMember); } while (in.hasNext()) { String removeMember = in.nextLine(); teamList.remove(removeMember); }    System.out.println("FINAL TEAM:"); System.out.println(teamList); in.close(); System.out.print("END OF OUTPUT"); } } =========================================================================================== //PoD import java.util.NoSuchElementException; /** * A listnked list is a sequence of nodes with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT