Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- =====================================================
- chapter 4: Loops
- Ex3: Display counter for same value & index
- =====================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- int num1,num2;
- int tmp1,tmp2;
- int count=0;
- //user input
- Scanner s=new Scanner(System.in);
- System.out.println("Enter 2 numbers: ");
- num1=s.nextInt();
- num2=s.nextInt();
- //keeping the number intact
- tmp1=num1;
- tmp2=num2;
- while(tmp1>0){
- if(tmp1%10==tmp2%10)
- count++;
- tmp1/=10;
- tmp2/=10;
- }
- System.out.println(count+" digits that have the same value & index");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement