Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoshua Thao
6,439 PointsHow to use this in Intellij instead of Jshell?
How would I make this work in IntelliJ instead of Jshell? When I run my program all I get is a test saying "Randomly picking 3 lunch spots".
public static String pickLunchSpot(String... spots){ System.out.printf("Randomly picking %d lunch spots. %n", spots.length); if (spots.length == 0){ return "Someplace with tacos"; } Random random = new Random(); // creates random selection return spots[random.nextInt(spots.length)]; // will not include the top number, will go 1 less }
public static void main(String[] args) { pickLunchSpot("Mexican Finests", "Pizza Hut", "Japanese Hibachi"); }
1 Answer
Emmanuel C
10,636 PointsTry creating a new project in intelliJ, then a new class to put this code in. The code works, but the string thats returns from spots doesnt get outputted, you can System.out.println the pickLunchSpot method, since it returns a string.
Also i had to "import java.util.Random"to use the random class
Joshua Thao
6,439 PointsJoshua Thao
6,439 Pointsyeah I cant get it to return the string even when I do this
pick.PickLunchSpots("Mexican Finests", "Pizza Hut", "Japanese Hibachi"); String places = pick.toString(); System.out.println(places);
Emmanuel C
10,636 PointsEmmanuel C
10,636 PointsTry this
The method pickLunchSpots returns a string, so you can assign it a variable then output it to console.