[英]How do I get the rightmost digits for step 1? Then how do I get the digits that weren't included for step 2?
import java.util.Scanner;
public class Ass. {
public static void main(String[] args) {
/*blanca 10/08/20
* 3.Following is a fun algorithm of three steps to check whether a given 8 digit number is acceptable.
* step1: starting from the rightmost digit,form the sum of every other digit.
* - For example the number is 12345658, this sum is 8+6+4+2 = 20.
* step2: double each of the digits that were not included in the preceding step; add all digits of the resulting number.
* - For the example number above,doubled digits would be 10,10,6,2. Adding those digits will yield (1+0+1+0+6+2)10.
* step3: Add the sum of the numbers in step1 and step2. if the last digit of that number is 0, the number is acceptable, not otherwise.
* Your program should read an 8 digit number and output whether it is acceptable or not.
*/
//declare
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
int digits = 0;
Scanner data = new Scanner(System.in);
System.out.println("Enter a card number");
digits = data.nextInt();
//step 1
sum1 = digits%10;
// step 2
sum2 = digits%100;
//step 3
sum3 = sum1 + sum2;
if (sum3 = 0){
System.out.println("Acceptable");
}
else
{
System.out.println("Unacceptable");
}
我看到了其他一些問題,看到位值(如 %10)應該給出數字,但我不知道如何根據問題更改它?
這里有一些建議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.