In: Computer Science
When all of the entries are valid, display an account number that shows first 3 digits of the telephone number and first two letters of the last name.
using name John Smith
phone number 1234567893
Using net beans take the first two letters from smith and first 3 numbers from the phone number and combine them to one line like this sm123.
#source code:
import java.util.*;
import java.lang.*;
public class Q{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String fname,lname,phonenumber;
System.out.print("Enter your first and last name:");
fname=sc.next();
lname=sc.next();
System.out.print("Enter your phone number:");
phonenumber=sc.next();
char[] varchar = phonenumber.toCharArray();
int count=0;
for(char c: varchar){
if(Character.isDigit(c)){
count=count+1;
}
}
if(count==10 &&phonenumber.length()==10){
String data;
char[] lnamec=lname.toCharArray();
data=Character.toString(lnamec[0])+Character.toString(lnamec[1]);
data=data.toLowerCase();
data+=Character.toString(varchar[0])+Character.toString(varchar[1])+Character.toString(varchar[2]);
System.out.println(data);
}else{
System.out.println("Nov valid phone number");
}
}
}
#output: