418
Подписчики
Нет данных24 часа
-27 дней
+1230 дней
Архив постов
Which keyword is used to explicitly throw an exception within a try block?
In which order are the blocks executed when an exception occurs within a try block?
Complete placement study material
https://drive.google.com/drive/folders/1SkCOcAS0Kqvuz-MJkkjbFr1GSue6Ms6m
ISBN Number Program In Java
public class ISBNValidation {
public static void main(String[] args) {
String isbn = "7426985414";
int sum = 0;
int weight = 1;
for (int i = isbn.length() - 1; i >= 0; i--) {
int digit = Character.getNumericValue(isbn.charAt(i));
sum += digit * weight;
weight++;
}
boolean isValid = sum % 11 == 0;
if (isValid) {
System.out.println("Valid ISBN");
} else {
System.out.println("Invalid ISBN");
}
}
}
ISBN Number in Java
ISBN stands for the International Standard Book Number that is carried by almost each every book. The ISBN is a ten-digit unique number. With the help of the ISBN, we can easily find any book.
Follow some steps to Solve ISBN Number
Take the ISBN number as input.
Calculate the weighted sum of the digits by multiplying each digit by its corresponding weight, starting from 1 for the rightmost digit and increasing by 1 for each subsequent digit from right to left.
Like :-
1*Digit1 + 2*Digit2 + 3*Digit3 + 4*Digit4 + 5*Digit5 + 6*Digit6 + 7*Digit7 + 8*Digit8 + 9*Digit9 + 10*Digit10
And after this some all digits and
divisible by 11 check whether the remainder is 0 or not. If the remainder is 0, the number is a Valid Otherwise, It is Invalid
*Example :- 8147852369
Sum = (1*9) + (2*6) + (3*3) + (4*2) + (5*5) + (6*8) + (7*7) + (8*4) + (9*1) + (10*8)
Sum = 9 + 12 + 9 + 8 + 25 + 48 + 49 + 32 + 9 + 80
Sum = 281
And after this check sum is divisible by 11 or not . If the remainder is 0, the number is a valid ISBN Otherwise invalid ISBN.
281 % 11 if reminder is 0 no valid Otherwise invalid
Using these steps, you can implement the ISBN number validation logic in Java or any other programming language.
