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.

Search

sfolax6776

Jul 16, 2018

3.7 How to read input from keyboard?

5 comments

Edited: Aug 27

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.

0

New Posts

- sfolax677613 hours agoA. Introduction A valid credit card number will yield a result divisible by 10 when you: Form the sum of all digits. Add to that sum every second digit, starting with the second digit from the right. Then add the number of digits in the second step that are greater than four. The result should be divisible by 10. For example, consider the number 4 0 1 2 8 8 8 8 8 8 8 8 1 8 8 1. The sum of all digits is 89. The sum of the bold digits is 46. There are five bold digits larger than four, so the result is 89+46+5=140. 140 is divisible by 10 so the card number is valid. B. Write your code to check if a credit card number is valid or not according to the rules above. You need to verify if the input is a 12-digit number.
- sfolax677614 hours agoA Introduction A drunkard in a grid of streets randomly picks one of four directions and stumbles to the next intersection, then again randomly picks one of four directions, and so on. You might think that on average the drunkard doesn’t move very far because the choices cancel each other out, but that is not the case. B Your task: Represent locations as integer pairs (x, y). Implement the drunkard’s walk over 100 intersections, starting at (0, 0), and print the ending location.
- sfolax67764 days agoA. Introduction Before we start learning computer programming, let's take a minute to understand what a computer is and have you ever wondered what are inside a computer? B. Watch ( Slides ) C. Try: there are many questions at end of chapter 1 of this book . See if you can do at least two of R1.2 - R1.4, E1.1-E1.3

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

system.inis a string and won't actually do anything.two variables are the same and therefore conflicts each other

in.readInt does not exist

1.lack “import java.util.Scanner;”

2.（“

Systam.in"),remove" "3.in read Int change in next Int

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...

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);

}

}