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 Harnessing the Power of Objects Overload Methods

polo solo
PLUS
polo solo
Courses Plus Student 437 Points

Second "String" problem Line 21... Skips and jumps to Line 22. Why?

Second "String" problem Line 21... Skips Scanner and jumps to Line 22. Why? Worked with "int"

GoKart.java
***
import java.util.Scanner;
public class apples{
   public static void main(String []ars ){
       Scanner sc = new Scanner(System.in);
       tuna tunaObject = new tuna();
      System.out.print("Sveiki! Kads ir tavs vards?\nIerakstit: ");
      String vards = sc.nextLine();
      tunaObject.iepazisanas(vards);
      System.out.print("Cik Jumsir gadi?\nIerakstit: ");
      int vecums = sc.nextInt();
      if (vecums>18){
      tunaObject.gadi1(vecums);
      }else{
          System.out.println("Atvainojiet!Jus neesat pilngadigs!\n");
          System.exit(0);
      }

      System.out.println("Laipni ludzam portala");
      System.out.println("Kads ir Jusu auto?");
      String Auto = sc.nextLine();
      tunaObject.scAutoAtbilde(Auto);


                   }    
}
import java.util.Scanner;
public class tuna {
    public void iepazisanas(String iepazisanasVards){
        System.out.println("Sveiki " + iepazisanasVards + "! "
                + "Priecajamies redzet musu portala!");
    }
    public void gadi1(int vecums){
        System.out.print("Lieliski! Jums ir " + vecums +" gadi\n");
    }
    public void scAutoAtbilde(String scZimols){
        System.out.println("Super! " + scZimols + "ir kvalitativs auto!\n");
    }
}
***

2 Answers