English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

write a program to display a person's name in the following style. for example the name:
William Jeffreson Clinton

would produce the output

Clinton, William J

2007-03-18 20:50:03 · 3 answers · asked by nur azhani 1 in Computers & Internet Programming & Design

3 answers

import java.io.*;
class asasasa
{
public static void main(String arg[]) throws IOException
{
BufferedReader buf= new BufferedReader(new InputStreamReade(System.In));
System.out.println("Enter first name: ");
String fname= buf.readLine();
System.out.println("Enter second name: ");
String sname= buf.readLine();
System.out.println("Enter last name: ");
String lname= buf.readLine();
System.out.println("new name style: " + lname + ", " + fname + " " + sname.substring(0,1));
}
}

2007-03-18 21:05:59 · answer #1 · answered by abd 5 · 0 0

A more malleable way would be to create a class to hold the data.
*FILE: Name.java*:
class Name
{
public String lname, mname, fname;
public Name(String lname, String mname, String fname)
{
this.lname=lname; this.mname=mname; this.fname=fname;
}
}

*FILE:Main.java*:
#import Name.java
class Main
{

public static void main(String[] args)
{
Name clinton = new Name("Clinton","Jefferson","William");
System.out.println(""+clinton.lname+", ");
System.out.println(""+clinton.fname+" ");
System.out.println(""+clinton.mname);
}
}

This is probably more like what you need. My syntax might be a little off.. i write mostly in C++ now an dhavent used java in a while.

2007-03-19 04:15:39 · answer #2 · answered by thomas p 2 · 0 0

#include
#include
main()
{ int arr[5][5] ; \* subscription of array *\
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
printf("\nEnter array elements");
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<5;i++)
{
for(j=o;j<5;j++)
{
printf("%d ",arr[i][j]);
}
}
getch();
}






DO IT :
Enter array element :76
Enter array element :6563
Enter array element :7678
Enter array element :8763
Enter array element :6565
Enter array element :2343
Enter array element :343
Enter array element :766
Enter array element :65
Enter array element :98
Enter array element :3
Enter array element :987
Enter array element :265
Enter array element :387
Enter array element :654
Enter array element :123
Enter array element :98
Enter array element :78
Enter array element :65
Enter array element :2
Enter array element :76
Enter array element :45
Enter array element :65
Enter array element :45
Enter array element :3


OUTPUT :76 6563 7678 8763 6565 2343 343 766 65 98 3 987 387 654 123 98 78 65 2 76 45 65 45 3

2007-03-19 04:14:26 · answer #3 · answered by raushan k 1 · 0 0

fedest.com, questions and answers