write a java program that first defines three string object called firstName,mid
ID: 3673346 • Letter: W
Question
write a java program that first defines three string object called firstName,middleName, lastName which contain your own first, middle and last name separately. if you do not have middlename then make it one. then try to generate a new user name for you by using first letter of you name (capitalized), first letter on you middle name(capitalized)plus all letters in your last name, add a random number between(1 to 100) to the your new user name. for example If you write name ABC DEF GHI than output should be ADGHI23 (any randrom number)
Explanation / Answer
package strings;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
public class Strings {
String first[]=new String[10];
String mid[]=new String[10];
String last[]=new String[10];
String firstName,midName,lastName;
String input;
int number=0;
int i=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Random r=new Random();
public Strings() throws IOException{
do{
System.out.println("Plese enter your first name");
first[i]=br.readLine();
System.out.println("Plese enter your middle name ");
mid[i]=br.readLine();
System.out.println("please enter your last name ");
last[i]=br.readLine();
System.out.println((first[i].charAt(0)+""+mid[i].charAt(0)+""+last[i]).toUpperCase()+""+r.nextInt(100));
System.out.println("To proceed press y/Y");
input=br.readLine();
}while(input=="y" || input=="Y");
}
public static void main(String[] args) throws IOException {
Strings s=new Strings();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.