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 Abstraction at Play

polo solo
PLUS
polo solo
Courses Plus Student 437 Points

Second "String" not working...Line 21 . It skips line 21. and jump to line 22. Works when change to "int". Why?

1.package boiling; 2.import java.util.Scanner; 3.public class apples{

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

    8. System.out.println("Laipni ludzam portala");
    9. System.out.println("Kads ir Jusu auto?");
    10. String Auto = sc.nextLine();
    11. tunaObject.scAutoAtbilde(Auto);
    12.        }    
      

      }

1.1.package boiling; 2.1.import java.util.Scanner; 3.1.public class tuna { 4.1. public void iepazisanas(String iepazisanasVards){ 5.1. System.out.println("Sveiki " + iepazisanasVards + "! " 6.1. + "Priecajamies redzet musu portala!"); 7.1. } 8.1. public void gadi1(int vecums){ 9.1. System.out.print("Lieliski! Jums ir " + vecums +" gadi\n"); 10.1. } 11.1. public void scAutoAtbilde(String scZimols){ 12.1. System.out.println("Super! " + scZimols + "ir kvalitativs auto!\n"); 13.1. } }

1 Answer