Question: What number will this code output 3 7 , 4 1 , 3 2 , or 1 8 ? public class Question { public static

What number will this code output 37,41,32, or 18?
public class Question {
public static int checksum(String number){
int total =0;
boolean multiply = false;
for (int i =0; i number.length(); i++){
int digit = Integer.parseInt(""+ number.charAt(i));
if (multiply){
digit *=3;
if (digit >10){
digit -=2;
}
}
total += digit;
multiply =!multiply;
}
return total;
}
public static void main(String[] args){
System.out.println(checksum("723481"));
}
}
What number will this code output 3 7 , 4 1 , 3 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!