Skip to content

Commit

Permalink
programming project chapter 3
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorw13 committed Jan 17, 2024
1 parent f4c4fa4 commit e77ad61
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class test {

public static void main(String[] args) {

System.out.println("Hello");
}

}
20 changes: 14 additions & 6 deletions username.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,38 @@ public class username
Then print a string composed of the first letter of the user's first name,
followed by the first five characters of
the user's last name, followed by a random number in the range 10 to 99.
Assume that the last name is at laset five letters long.
Assume that the last name is at least five letters long.
Similar algorithms are sometimes used to generate usernames for new computer accounts.
*/-----------------------------------------------------------------
*/

public static void main(String[] args)

{
Random generator = new Random();

String userfirstname;
String userlastname;
int usernumber;

Scanner scan = new Scanner(System.in);
usernumber = generator.nextInt();
usernumber = generator.nextInt((0) + 99);

System.out.print("What is your first name?");
userfirstname = scan.nextLine();
System.out.println("What is your last name?");
userlastname = scan.nextLine();

String newfirst = userfirstname.substring(0,1);
String newlast = userlastname.substring(0,5) ;

System.out.println(" First Name is: " + userfirstname );
System.out.println(" Last Name is: " + userlastname );
System.out.println("New User First name is " + userfirstname.charAt(1) );
System.out.println("New User Last name is " + userlastname.substring(1,5) );
System.out.println("Random number is:" + usernumber);
//System.out.println("New User First name is " + userfirstname.charAt(0) );
// System.out.println("New User Last name is " + userlastname.substring(0,5) );
System.out.println("Random number is:" + usernumber );

System.out.println("New Username:" + newfirst + newlast + usernumber);

}


Expand Down

0 comments on commit e77ad61

Please sign in to comment.