Create an array that receives [ name, surname, gender, age]
o Prompt user to enter those variables.
o Display list of users
Headings
• Name | Surname | Gender | Age
o Make use of For loop to run prompt and display your array.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
System.out.println("Hello World");
String arr[]= new String[4];
Scanner in =new Scanner(System.in);
System.out.println("Enter name, surname, gender, age: ");
for(int i=0;i<4;i++){
arr[i]=in.next();
}
System.out.println("Name | Surname | Gender | Age: ");
for(int i=0;i<4;i++){
System.out.print(arr[i]+" | ");
}
}
}
Comments
Leave a comment