Consider the following two-dimensional array:
String [ ][ ] states = { { "CA", "CO" },
{ "MD", "IL", "ME", "MI" }, { "NY", "NJ", "NE" } };
What is the value of states[2][1] ?
Retrieve ME from the array states and assign it to a String variable of your choice
Using a loop, output all the states that start with the letter M in the second row (as in this example); assume that you do not know how many columns are in the second row, i.e. DO NOT hard code 4; assume that you do not know that the 3 states are MD, ME, MI
String [ ][ ] states = { { "CA", "CO" }, { "MD", "IL", "ME", "MI" }, { "NY", "NJ", "NE" } };
So the first row i.e, states[0] has "CA", "CO"
The second row i.e, states[1] has "MD", "IL", "ME", "MI"
The third row i.e, states[2] has "NY", "NJ", "NE"
So states[2][1] is nothing but second element in third row i.e, "NJ"
Code:
public class Main
{
public static void main(String args[]) throws Exception
{
String [ ][ ] states = { { "CA", "CO" },{ "MD", "IL", "ME", "MI" }, { "NY", "NJ", "NE" } };
String s=new String();
s=states[1][2];//retrieving ME and assigning to s
System.out.println("The string retrieved and stored in s is "+s);
System.out.print("The states that start with letter M in second row are: ");
for(int i=0;i<states[1].length;i++)//note that we have not used 4 here
if(states[1][i].charAt(0)=='M')//checking if first letter in string is M
System.out.print(states[1][i]+" ");//printing the state is condition is satisfied
}
}
Screenshot of code and output:

Consider the following two-dimensional array: String [ ][ ] states = { { "CA", "CO" },...
create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...
It's python. Please don't forget to print alpha-sorted states. Not random. Thank you // USPresdients.txt KY Abraham_Lincoln SC Andrew_Jackson NC Andrew_Johnson HI Barack_Obama OH Benjamin_Harrison AR Bill_Clinton VT Calvin_Coolidge VT Chester_A_Arthur NY Donald_Trump TX Dwight_D_Eisenhower NY Franklin_D_Roosevelt NH Franklin_Pierce MA George_H_W_Bush CT George_W_Bush VA George_Washington NE Gerald_R_Ford NJ Grover_Cleveland MO Harry_S_Truman IA Herbert_Hoover OH James_A_Garfield PA James_Buchanan NC James_K_Polk VA James_Madison VA James_Monroe GA Jimmy_Carter MA John_Adams MA John_F_Kennedy MA John_Quincy_Adams VA John_Tyler TX Lyndon_B_Johnson NY Martin_Van_Buren NY Millard_Fillmore CA ...
in java / You will: // 1- create a square 2 dimensional array of random size (less than 11) // 2- fill the array with random integers from 1 to the size limit // 3- print the array // 4- prompt to see if the user wants to do another //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 1- The square can use the same random value for x and y. Don't allow 0 size arrays. // 2- Maybe a nested set of for loops? to...
Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...
please answer in Java..all excercises. /** * YOUR NAME GOES HERE * 4/7/2017 */ public class Chapter9a_FillInTheCode { public static void main(String[] args) { String [][] geo = {{"MD", "NY", "NJ", "MA", "CA", "MI", "OR"}, {"Detroit", "Newark", "Boston", "Seattle"}}; // ------> exercise 9a1 // this code prints the element at row at index 1 and column at index 2 // your code goes here System.out.println("Done exercise 9a1.\n"); // ------> exercise 9a2 // this code prints all the states in the...
C++ Program - Arrays- Include the following header files in your program: string, iomanip, iostream Suggestion: code steps 1 thru 4 then test then add requirement 5, then test, then add 6, then test etc. Add comments to display assignment //step 1., //step 2. etc. This program is to have no programer created functions. Just do everything in main and make sure you comment each step. Create a program which has: 1. The following arrays created: a. an array...
and MT NE NV ND NH NJ NM NY NC OH OK OR PA RI SC SD TN TX UT VA VT WA WV WI WY EM 95813624 7262 1430278 3 22896 03171 12111 1165380 2111211 1.0160 72221 8 tat-AL AK AZ CA CO CN DE DC FL GA HI ID IL IN IA KA KY LA ME MD MA MI MN MS MO ONEC EDA-NSO git M w w M w w E E E E E W W...
C programming 1) When setting a two-dimensional character array, how is the size (number of characters) in the second dimension set? Select an answer: The number of elements are equal to the average size of all the strings. To the length of the longest string; you don't need to add one because the first array element is zero. To the length of the longest string, plus one for the null character. The second dimension is equal to the number of...
Maze Solving with Stacks Problem Statement Consider a maze made up of rectangular array of squares, such as the following one: X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X Figure...
JAVA Create a Governor class with the following attributes: name : String party - char (the character will be either D, R or I) ageWhenElected : int Create a State class with the following attributes: name : String abbreviation : String population : long governor : Governor Your classes will have all setters, getters, typical methods to this point (equals(), toString()) and at least 3 constructors (1 must be the default, 1 must be the copy). You will be turning...