Hi I need some help compiling this program


#1


< It does not compute correctly no error messages.>


`

`


#2

If there are no error message then doesn't that indicate that it successfully compiled? What's the issue? "not correct" doesn't describe what should have happened and what does happen
Also note that we can't execute your screenshot, text is a better medium for code.


#3

// true it is logical I will write it below

import java.util*;
public class ColorFinder{
public static void main(String[] args){
Scanner kbd = new Scanner(System.in);

String colorFind;
System.out.println("Enter a sentence.");
colorFind = kbd.nextLine();

switch (colorFind) (
case "red":
System.out.println("Additive primary color found.");
break;
case "green":
System.out.println("Additive primary color found.");
break;
case "blue":
System.out.println("Additive primary color found.");
break;
case "magenta":
System.out.println("subtractive primary color found.");
break;
case "yellow":
System.out.println("subtractive primary color found.");
break;
case "cyan":
System.out.println("subtractive primary color found.");
break;
default:
System.out.println("No primary color found.");

}

kbd.close;

}

}


#4

Still no clue what I would look for. What's the issue? What are you trying to change about it?

Compiling that does result in compile errors. Since you said that there are no error messages, that indicates that you aren't invoking the compiler correctly

Also it's different from the code in the screenshot.


#5

I apologize, every time I execute the program it returns with: No primary color found. Despite putting "blue" or another color in the sentence.


#6

The code you gave me doesn't have that behaviour - it doesn't compile >.>

Anyway, if it's not matching any of the cases then the string is probably different and so the next thing to do is to look at the string


#7

After fixing the compilation errors, it behaves this way:

$ java ColorFinder 
Enter a sentence.
blue
Additive primary color found.

..which again isn't what you describe.


#8

Again I apologize I am truly ignorant to programming.... when I said no errors I meant no red marks in Eclipse. I need help spotting and correcting my compilation errors.


#9

Pretty sure eclipse pops up compilation errors when you tell it to compile and it doesn't.

You could cut out eclipse and invoke the compiler directly on your code:

$ javac ColorFinder.java
$ java ColorFinder
Enter a sentence.
blue
Additive primary color found.
$

The red marks in eclipse are quite possibly the compilation errors though. And those would be doing exactly what you're asking for, spotting the locations of the errors, describing them as well.

There are also a bunch of websites where you can paste your code and get the compilers messages (including the codecademy exercises, but googling for others is about as easy)


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.