Question: I have created a Java program that needs an output of: 5 0 7 5 4 9 8 changed to 5 0 1 2 1

I have created a Java program that needs an output of: 5075498
changed to 5012102. However, the closest I can get is 5075498 changed to 20012102.
Below is my Java program. What am I missing or how can I modify my code to have the output: 5075498 changed to 5012102. I cannot use string methods, IF statements, or loops. Only supposed to use the arithmetic patterns below to convert 5075498 to 5012102.
_______________________________________
import java.util.Scanner;
public class HW1CharityHubbard {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter a 7-digit integer: ");
int n = input.nextInt();
int d1=(n /1000000)%10;
int d2=(n /100000)%10;
int d3=(n /10000)%10;
int d4=(n /1000)%10;
int d5=(n /100)%10;
int d6=(n /10)%10;
int d7= n %10;
d1=(d1%10)%3;
d2=(d2%10)%3;
d3=(d3%10)%3;
d4=(d4%10)%3;
d5=(d5%10)%3;
d6=(d6%10)%3;
d7=(d7%10)%3;
int r = d1*10000000+ d2*100000+ d3*10000+ d4*1000+ d5*100+ d6*10+ d7;
System.out.println(n +" changed to "+ r);
}
}

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!