
Hello there,
why the output only catch the last input? can you correct my coding here? This is my first time exploring Java.
import javax.swing.*;
class JOPtionPaneExample {
public static void main(String[] args)
{
int i = 0;
final int k = 5;
String name;
int age;
while(i < k)
{
name=JOptionPane.showInputDialog(null,"Enter
Name: ");
age=Integer.parseInt(JOptionPane.showInputDialog(null,
"Enter Age: "));
JOptionPane.showMessageDialog(null,
"Name is: "+name+" and Age is:
"+Integer.toString(age));
i++;
if(i==k)
{
System.out.println("Name is: "+name+" and Age is:
"+Integer.toString(age));
}
}
} }

import javax.swing.*;
class JOPtionPaneExample{
public static void main(String[] args){
int i = 0;
final int k = 5;
String array[]=new String[5];
int arr[]=new int[5];
while(i < k){
String name=JOptionPane.showInputDialog(null,"Enter Name: ");
int age=Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Age: "));
array[i]=name;
arr[i]=age;
i++;
}
for(int j=0;j<5;j++){
JOptionPane.showMessageDialog(null, "Name is: "+array[j]+" and Age is: "+Integer.toString(arr[j]));
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.