1.
Create a Java program named PE1Lastname. (ex. PE1Dela_Cruz)
2.
Initialize the following variables based on the table below:
DATA TYPE
VARIABLE NAME
VALUE
String
firstName
Type your first name
String
lastName
Type your last name
char
mi
Type your middle initial
int
age
Type your age
char(array)
nickNameArray
Every index should contain each of the
letters of your nickname.
3.
Use scanner class for data entry. Use comments to give a short description of
the parts of the program. (//Single-line comments and /**/multi-line comments)
4.
Produce an output similar to the sample below.
5.
The nickname should be inside an array variable. You should be able to display
each letters.
import java.util.Scanner;
public class PE1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Type your first name");
String firstName = in.nextLine();
System.out.println("Type your last name");
String lastName = in.nextLine();
System.out.println("Type your middle initial");
char mi = in.nextLine().charAt(0);
System.out.println("Type your age");
int age = Integer.parseInt(in.nextLine());
System.out.println("");
char[] nickNameArray = in.nextLine().toCharArray();
System.out.print(firstName + " " + mi + " " + lastName + " " + age + " ");
for (int i = 0; i < nickNameArray.length; i++) {
System.out.print(nickNameArray[i]);
}
System.out.println();
}
}
Comments
thank you very much...
Leave a comment