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 trial

Java Nesting Loops

Chidiebere Ekennia
Chidiebere Ekennia
5,950 Points

My code isn't working

import java.io.Console; import java.util.Random;

public class NestingLoops {

public static void main(String[] args) {

  Console console = System.console();

//This is my code:

  String [] sweetFlavors {"Caramel", "Cinnamon", "Watermelon", "Baked Beans"};

  String [] savoryFlavors {"Sea Salt", "Potato Chip", "Carrot", "Barbeque Sauce"};

  for (String sweet: sweetFlavors) {
  for (String savoury: savoryFlavors) {
  console.printf("%s and %s %n", sweet, savory);
                                                  }
        }

  }

}

I'm getting this error: NestingLoops.java:10: error: ';' expected
String [] sweetFlavors {"Caramel", "Cinnamon", "Watermelon", "Baked Beans"};
^
NestingLoops.java:10: error: not a statement
String [] sweetFlavors {"Caramel", "Cinnamon", "Watermelon", "Baked Beans"};
^
NestingLoops.java:10: error: ';' expected
String [] sweetFlavors {"Caramel", "Cinnamon", "Watermelon", "Baked Beans"};
^
NestingLoops.java:12: error: ';' expected
String [] savoryFlavors {"Sea Salt", "Potato Chip", "Carrot", "Barbeque Sauce"};
^
NestingLoops.java:12: error: not a statement
String [] savoryFlavors {"Sea Salt", "Potato Chip", "Carrot", "Barbeque Sauce"};
^
NestingLoops.java:12: error: ';' expected
String [] savoryFlavors {"Sea Salt", "Potato Chip", "Carrot", "Barbeque Sauce"};
^
6 errors

2 Answers

You are missing assignment operators:

String [] sweetFlavors {"Caramel", "Cinnamon", "Watermelon", "Baked Beans"};
String [] savoryFlavors {"Sea Salt", "Potato Chip", "Carrot", "Barbeque Sauce"};

should be:

String [] sweetFlavors = {"Caramel", "Cinnamon", "Watermelon", "Baked Beans"};
String [] savoryFlavors = {"Sea Salt", "Potato Chip", "Carrot", "Barbeque Sauce"};

You also have a misspelling of savory here:

for (String savoury: savoryFlavors)