Answer to Question #237657 in Java | JSP | JSF for sandyJay

Question #237657

The statements below shows the declaration of an array:

 

String[] Municipality ={”Steve Tshwete”, “Nkomazi”, “City of Mbombela”, “Govan Mbeki”};

 

1) Make use of a loop of your choice and write statement(s) that will display all array elements indicating the Municipality’s name as follows:

 

Municipality 1: Steve Tshwete

Municipality 2: Nkomazi

Municipality 3: City of Mbombela

Municipality 4: Govan Mbeki

 

1) Write a statement that will replace array element Nkomazi with White River.

3) What is the array length?

4) Make use of a loop of your choice and write statement(s) that will display all Municipalities, considering effects of question (2), starting with the last Municipality as shown below:

 

Municipality 4: Govan Mbeki

Municipality 3: City of Mbombela

Municipality 2: Nkomazi

Municipality 1: Steve Tshwete


1
Expert's answer
2021-09-15T23:39:57-0400


public class Main
{
	public static void main(String[] args) {
	   //1
		String[] Municipality ={"Steve Tshwete", "Nkomazi", "City of Mbombela", "Govan Mbeki"};
		for(int i=0;i<4;i++){
		    System.out.println("Municipality "+(i+1)+":"+Municipality[i]);
		}
		System.out.println();
	//4
	    for(int i = 3; i >= 0; i--){
		    System.out.println("Municipality "+(i+1)+":"+Municipality[i]);
		}
	// 1) Write a statement that will replace array element Nkomazi with White River.
	    Municipality[1]="White River";
	   // What is the array length?
	   int length=Municipality.length;
	   System.out.println(length);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS