Module 1 Assignment:

This
assignment is an individual assignment. 

  1. (20
    pts) What is the output of this code sequence? (Be exact in your answer with
    spacing)

double [] a = {12.5, 48.3, 65.0};

System.out.println(a[1]);

  • (20pts) What is the output of this code sequence? (Be exact in your answer with spacing)

int [ ] a = {12,48,65};

for (int i=0; i <a.length;i++)

  
System.out.println(“a[“ +i+”] = “+ a[i]);

  • (20
    pts) What does this method do?

public static int foo(String [] a)

 
  {

   
int b = 0;

   
for (int i = 0; i<a.length; i++)

      
{

               b++;

      
}

     
return b;

  • (40
    pts) You coded the following on line 26 of a program called Test.java:

int a[6] = {2,7,8,9,11,16);  //line 26

When you compile, you get the following messages:

Test.java:26: ‘]’ expected

    int
a[6] = {2,7,8,9,11,16}; //line 26

            
^

Test.java:26: illegal start of expression

     
int a[6] = {2,7,8,9,11,16}; //line 26

                ^

            Test.java:26: illegal start of expression

                 int a[6] =
{2,7,8,9,11,16};//line 26

                                 ^

            Test.java:26: not a statement

                 int a[6] = {2,7,8,9,11,16};
//line 26

                                   ^

            Test.java: 26: “;” expected

                 int a[6] = {2,7,8,9,11,16};
//line 26

                                     ^

            Test.java: 26: class, interface, or
enum expected

            }

            ^

            6 errors

 What is the error in line 26? How do you correct it?

Sample Solution

find the cost of your paper