You are on page 1of 3

Model Answers

Part 1
Code Snippets – follow tasks requirements and provide code to attain required output/result

1.Sort the people by name and return as a comma separated string.

$people = array( 'Mary' => 17, 'Bob' => 62, 'John' => 32, );
function list_people($people) {
public static void main(String[] people)
{
String arrString[] = { "Mary", "Bob", "John" };
peoplename(arrString);
}

public static void peoplename(String[] people)


{
Arrays.sort(people);
System.out.println(Arrays.toString(people));
}
}

}
print list_people($people);

2. Sum all integers from $start to $end (included) and print the result.

$start = 1; $end = 3;

public class IntegerSumExample1 {  
   public static void main(String[] args) {          
        
        System.out.println("The sum of a and b is = " + Integer.sum($start, $end));  
    }  
}  

3. Script should print "Go outside" only if: it is NOT raining AND it is warm OR it is daytime.

$raining = FALSE; $warm = TRUE; $daytime = FALSE;

  
import java.io.*;
  
class raining {

public class Main {


public static void main(String[] args) {
if (x =not raining && warm && daytime) {
System.out.println("Go outside");

else

System.out.printIn (“Stay Inside “);


}

4. Write pseudo-code to display exactly 100 input box. Every 4th input box, display a 'x'.

(css style and arrangement is not important)

 
for(int i = 1; i <= 100; i++) {
    print i;
}

if ( i=4)
System.out.printIn (“x”)

5. Mathematics: Write down the formula/equation to calculate the following.


Price after 20% discount = $1000
What is the price before discount / original price ?

class Discount
{
public static void main(String args[])
{

double dis,amount,markedprice,s;

markedprice=1000;
dis=20;

System.out.println("markedprice= "+markedprice);

System.out.println("discount rate="+dis);

s=100+dis;

amount= (s*markedprice)/100;

System.out.println("amount after discount="+amount);

}
}

You might also like