How do declare array in various format write a java program


Assignment

Question 1

Do as Directed. (Each question will have 1 mark)

(i) What will be output of the following code?

inti = 0;
while (i != 9)
{
System.out.println("" + i);
i = i + 2;
}

(ii) What will be the output of the following code?

inti = 1;
int sum = 0;
while (i<= 11)
{
sum = sum + i;
i++;
}

System.out.println("The value of sum is " + sum);
System.out.println("The loop will continue " + i + " times.");

(iii) How many times does the following Java code display "Java Program" output?

for (inti = 0; i< 10; i++);
{
System.out.println(" Java Program ");
}

(iv) In the following code, How many times the output "My Name" will be print?

intp;
int q;
for (p = 0; p <= 9; p++)
{
for (q = p; q < 5; q++)
{
System.out.println("My Name");
if (q == 2)
{
q = 6;
}
}
}

Question 2

Write a program in Java using "Nested For" Loop to print Diamond star pattern.

*
**
***
*** *
**** *

Provide a screenshot of your work.

Question 3

Write a short notes on Following topics.

a. What is an Array?

b. How do declare array in various format?

c. Define Array List.

d. Give an example for add and remove array element.

Question 4

Write a Java Program to display following output using Array List.

Before 2015 Saudi Electronic University Branch: 0

After 2015: 7

Number of Branch: [Dammam, Tabuk, Jeddah, Madinah, Al Qassim, Abha, Al Jouf]

Number of Branch after deletions: 5

Total of Branch: [Dammam, Tabuk, Madinah, Al Qassim, Al Jouf]

Provide a screenshot of your work.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: How do declare array in various format write a java program
Reference No:- TGS02534601

Now Priced at $25 (50% Discount)

Recommended (99%)

Rated (4.3/5)