0

Java Problem:Credit card validator

import java.util.*; public class Program { public static void main(String[] args) { Scanner x = new Scanner(System.in); int counter =0; int allnumbs=0; int check =0; String y = x.nextLine(); String g =""; for(int i =15;i>=0;i--) {g+=y.charAt(i);} check = g.length(); String[] i = g.split(""); if(check==16){ for(String j : i) {counter++; int calc = Integer.parseInt(j); if (counter%2==0){calc*=2;} if (calc>9){calc-=9;} allnumbs+=calc; } allnumbs%=10; if(allnumbs==0){ System.out.println("valid");} else{System.out.println("not valid");} }else if(check!=16){System.out.println("not valid");} } } Only 5 out of 7.dont get it why I'm stuck now. Problem Link: https://www.sololearn.com/coach/96?ref=app Need help :D(not the solution just hints) https://code.sololearn.com/cla8bgxSW0f6/?ref=app

10th Sep 2022, 9:02 AM
Jannis Kretzler
Jannis Kretzler - avatar
4 Antworten
+ 3
sorry but this is pro question. we cant access it 😅.. wait till any pro user answer it
10th Sep 2022, 9:14 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 2
Thanks anyway! Did fix it, the reverse for loop didn't check if the string length is 16 before adding the numbers in reverse to the second string. The last two inputs are under 16 digits long and created an error because of this. Thank you for showing me that the playground exists lol. Very useful :)
10th Sep 2022, 9:18 AM
Jannis Kretzler
Jannis Kretzler - avatar
+ 1
you can put this code in code playground and share a link so that we can help you better by pin pointing line of code ...
10th Sep 2022, 9:04 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 1
Didn't know that this was possible, sorry. Did add it.
10th Sep 2022, 9:13 AM
Jannis Kretzler
Jannis Kretzler - avatar