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 Java Objects (Retired) Harnessing the Power of Objects Incrementing and Decrementing

Stuck

I am making a program, but there is someting wrong (3 errors), but I don't know, how to fix it.

Here is the program:

import java.io.Console;
public class Vzem { 
  public static void main(String[] args) {
      int k1 = 0;
      int k2 = 0;
      int k3 = 0;


  public void result() {
   if (k1 > 49 || k2 > 49 || k3 > 49) {
     console.javac("-----------------------");
   }

   if (k1 > 49) {
    system.out.println("1");
   }

   if (k2 > 49) {
    system.out.println("2");
   }

   if (k3 > 49) {
    system.out.println("3");
   }


  }

}
}

And here are the errors:

Vzem.java:13: error: illegal start of expression
public void result() {                                                                                                                                                                                                                                                                          
^                                                                                                                                                                                                                                                                                                 
Vzem.java:13: error: illegal start of expression                                                                                                                                                                                                                                                                                               public void result() {                                                                                                                                                                                                                                                                          
           ^                                                                                                                                                                                                                                                                                          
Vzem.java:13: error: ';' expected                                                                                                                                                                                                                                                                   
public void result() {                                                                                                                                                                                                                                                                          
                             ^                                                                                                                                                                                                                                                                             
3 errors

Please help.

at: public void result() { if (k1 > 49 || k2 > 49 || k3 > 49) { CONSOLE.JAVAC("-----------------------"); } I write console.javac instead of console.printf.

4 Answers

Alex White
Alex White
16,750 Points

That is an error you should be able to solve easily via Google or even better the Java documentation. See here: https://docs.oracle.com/javase/7/docs/api/java/lang/System.html

system is a class not a method which means you have made a common typo. In Java classes begin with a capital letter so it should read:

System.out.println("");

Thanks.

You cannot call a non-static method inside public static void main. If you want to use the method result, you need to add the static keyword to it.

Alex White
Alex White
16,750 Points

You are creating a method inside another method, which you cannot do. You can have multiple methods in a class and you can call methods from methods but cannot create methods inside methods. refactored:

public class Vzem {
    public static void main( String[] args ) {
        ....
    }
    public static void result() {
        ...
    }
}

then from inised the 'main' you would call 'result();' or if you wanted result method to not be static as you have written above then you would instantiate the Vzem class inside 'main' and call the method from that:

Vzem vzem = new Vzem();
vzem.result();

Thank you for solving that problem, but now there is one more thing to fix (I don't know, what is wrong).

Program

import java.io.Console;
public class Vzem { 
      int k1 = 0;
      int k2 = 0;
      int k3 = 0;


  public void result() {
   if (k1 > 49 || k2 > 49 || k3 > 49) {
     system.out.println("-----------------------");
   }

   if (k1 > 49) {
    system.out.println("1");
   }

   if (k2 > 49) {
    system.out.println("2");
   }

   if (k3 > 49) {
    system.out.println("3");
   }


  }

}

Errors:

Someting.java:10: error: package system does not exist                                                                           

     system.out.println("-----------------------");                                                                              

           ^

Someting.java:14: error: package system does not exist                                                                           

    system.out.println("1");                                                                                                     

          ^                                                                                                                      

Someting.java:18: error: package system does not exist                                                                           

    system.out.println("2");                                                                                                     

          ^                        

Someting.java:22: error: package system does not exist                                                                           

    system.out.println("3");      

          ^          

Please help (again).