Computer Science, asked by paulsoham049, 7 hours ago

write a program to enter your date of birth in the form of DD MM YY and calculate the lucky digit​

Answers

Answered by ishukapoor3313
0

Answer:

import java.util.Scanner;

public class LuckyNumber {

public static void main(String[] args) {

int luckyNumber=0;

System.out.println("Enter the DOB in dd/MM/yyyy format:");

Scanner input=new Scanner(System.in);

String dob=input.nextLine();

for(int i=0;i<dob.length();i++){

if(dob.charAt(i)!=´/´){

/*Sum of all the digits in the DOB*/

luckyNumber=luckyNumber+Integer.parseInt(String.valueOf(dob.charAt(i)));

}

}

System.out.println("Lucky Number: "+getOneDigit(luckyNumber));

}

public static int getOneDigit(Integer number){

int result=number;

while(number.toString().length()>1){

result=0;

for(int i=0;i<number.toString().length();i++){

result=result+Integer.parseInt(String.valueOf(number.toString().charAt(i)));

}

number=result;

}

return result;

}

}

Explanation:

Similar questions