I am brand new at coding and can not get my application to run right. Please help!
I have written the following code for a HW assignment:
import java.util.Scanner;
public class HW1Q2
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String sentence, str1, str2;
System.out.println("Enter a sentence containing either the word \"blue\" or the word \"green\" both or neither");
sentence = keyboard.nextLine();
str1 = "blue";
str2 = "green";
if(sentence.contains("blue")); if(sentence.contains("green")){
System.out.println("sunny");}
else{
if(sentence.contains("blue")){
System.out.println("ocean");}
else{
if(sentence.contains("green")){
System.out.println("garden");}
else{
System.out.println("dull");
}}}
}
}
The goal is to return
gardenif they typegreenoceanif they typebluesunnyif they type both anddullif they type neither
The problem is if I write a sentence that only includes green, it still returns sunny not garden.
Aucun commentaire:
Enregistrer un commentaire