Question: Please help in JAVA: The input consists of an integer (the number of elements in the array), followed by the elements of the array. Method

Please help in JAVA:

The input consists of an integer (the number of elements in the array), followed by the elements of the array. Method Add will add the elements of the array and return that value (the total) to main. Method printResult will take that total and print the following: if the total is divisible by 5, it will print "You lose!" If the total is exactly 21, it will print "You win!" Otherwise it will print "Try again." In each case use a println.

This is the code given:

import java.util.Scanner;

public class Lab1Num1 {

public static void main(String[] args) {

//get the input

int[] myArray=getInput();

//add the integers

int total=Add(myArray);

//determine win or lose or try again.

printResult(total);

}

public static int[] getInput()

{ Scanner keyboard = new Scanner(System.in);

//find the length of the array

int num = keyboard.nextInt();

//create the array

int[] myA= new int[num];

//fill the array

for (int i=0; i

myA[i]=keyboard.nextInt();

return myA;

}

public static int Add(int[]myA)

{ //your code goes here

}

public static void printResult(int t)

{ //your code goes here

}

}

Thank you!!

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!