Answer to Question #297158 in Java | JSP | JSF for ivy

Question #297158

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.


1
Expert's answer
2022-02-13T04:01:57-0500
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();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

maja
20.02.22, 11:29

thank you very much...

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS