Question: Provide the output for the following code fragment: 1 mark for each correct output: String r = new String (Always think you are something); String

Provide the output for the following code fragment:

  1. 1 mark for each correct output:

String r = new String ("Always think you are something");

String m = new String("You can achieve anything");

StringBuffer n= new StringBuffer("entertainment");

String c = new String();

System.out.println(r.toUpperCase());

System.out.println(m.toLowerCase());

System.out.println(r.replace('o', 'A'));

System.out.println(m.length());

System.out.println(r.substring(4));

System.out.println(r.substring(7,12));

System.out.println(m.indexOf('t'));

System.out.println(m.indexOf('i',6));

System.out.println(m.charAt(5));

System.out.println(n.reverse());

  1. 5 marks-1 mark each for the correct output with working

public class SA2_3

{

public static void main(String[] arg)

{

int [ ]marks = {3,2,1,8,5};

convert( marks );

for( int i=0; i

System.out.println( marks[i] );

}

public static void convert( int[ ] arr )

{

for( int i=0; i

{

arr[i] =arr[i] + 10;

}

}}

c. 5 marks-2.5 mark for the correct output 2.5 marks for the working

public class SA2_1

{

public static void main(String[] arg)

{

int a[ ]= {12,3,9,4,8};

System.out.print("output will be:");

System.out.println(function1(a));

}

public static int function1(int x [ ])

{

int sum=0;

for (int i=0; i<5;i++)

{

sum = sum + x[i];

}

return sum;

}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!