logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    sfolax6776
    Jul 16, 2018
      ·  Edited: Aug 27, 2019

    3.7 How to read input from keyboard?

    in Introduction to Java

    Read section 4.1.3 on page 145 first, then complete R4.12 on page 164. Please feel free to copy and paste the code below to Codiva and try.


    4 comments
    0
    tian
    Jul 18, 2018

    1. this is a compile time error, but readInt doesn't exist, nextInt does though

    2. after the second System.out.print, x should be y

    3. the scanner shouldn't be initialized with a string

    0
    wangernestrdragon
    Jul 18, 2018

    system.in is a string and won't actually do anything.

    two variables are the same and therefore conflicts each other

    in.readInt does not exist

    0
    sfolax6776
    Jul 23, 2018

    You all get some of the corrections, but not ALL of them. If you test your corrections in Codiva, you will see what else is missing...

    0
    mr.ricklu
    Jul 23, 2018

    correct code:

    import java.util.Scanner;


    public class HasError

    {

    public static void main(String[] args)

    {

    int x = 0;

    int y = 0;

    Scanner in = new Scanner(System.in);

    System.out.print("Please enter an integer:");

    x = in.nextInt();

    System.out.print("Please enter another integer: ");

    y = in.nextInt();

    System.out.print("The sum is ");

    System.out.print(x + y);

    }

    }

    4 comments

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2020 Legion of Learners