0

Use your newfound knowledge of arrays, input and for loops to make a program that takes in text input (names) from the user, stores each one in the elements of an array and then prints out one name (randomly generated using Math.random()) of the person who has to get off the lifeboat.

so far I have

public class Int 
{

    public static void main(String[] args) 
    {
        // TODO Auto-generated method stub


        {
            String[] names = { "mary", "sue", "jen", "sally", "pam", "jordan", "bob", "calvin", "kevin", "mike", "brendan" };

            int length = names.length;

            for (int i = 0; i < length; i++)
            {

                System.out.print(" ");
            }
            int rand = (int) (Math.random() * length);

            System.out.print(names[rand] + " will be thrown overboard");
        } 

    }
}

but teacher says I have to use input i.e. scanner. please help

Yassin Hajaj
  • 20,020
  • 9
  • 41
  • 81
bwilbz
  • 1
  • 1
  • 1
    https://docs.oracle.com/javase/tutorial/essential/io/cl.html – Meiko Rachimow Mar 16 '16 at 12:19
  • 1
    google search on this topic yeilds a lot of results. Plz try that first. https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&es_th=1&ie=UTF-8#q=java%20scanner%20read%20console%20input – Balaji Krishnan Mar 16 '16 at 12:19

0 Answers0