Posts

Showing posts from March, 2019

Vinuesa

Image
An Vinuesa amo an usa ka bungto ha Provincia de Soria, Castilla y León, Espanya. igliwat Mga Bungto han Provincia de Soria Abejar  · Adradas  · Ágreda  · Alconaba  · Alcubilla de Avellaneda  · Alcubilla de las Peñas  · Aldealafuente  · Aldealices  · Aldealpozo  · Aldealseñor  · Aldehuela de Periáñez  · Alentisque  · Aliud  · Almajano  · Almaluez  · Almarza  · Almazul  · Almazán  · Almenar de Soria  · Alpanseque  · Arancón  · Arcos de Jalón  · Arenillas  · Arévalo de la Sierra  · Ausejo de la Sierra  · Baraona  · Barca  · Barcones  · Bayubas de Abajo  · Bayubas de Arriba  · Beratón  · Berlanga de Duero  · Blacos  · Bliecos  · Borjabad  · Borobia  · Buberos  · Buitrago  · Burgo de Osma-Ciudad de Osma  · Cabrejas del Campo  · Cabrejas del Pinar  · Calatañazor  · Caltojar  · Candilichera  · Carabantes  · Caracena  · Carrascosa de Abajo  · Carrascosa de la Sierra  · Casarejos 

Why is initializing a string in an if statement different than in a switch statement?

Image
7 I'm learning Java and I'm making simple programs to find the season that a month is in, based off some book examples. These two classes demonstrate two ways of testing a value: if/else if statement, and switch statement. The thing i'm confused with is the string that is used to hold the season. When I declare it as just String season; it works with the if statements. But with the switch statement, doing that produces a "The local variable season may not have been initialized" error. public class IfElse { public static void main(String args) { int month = 5; String season; // isn't initialized, works fine if(month == 12 || month == 1 || month == 2) season = "Winter"; else if(month == 3 || month == 4 || month == 5)