A java program that accepts one string as input

Example Input:
Bleach,22,13,TiteKubo

Output:
Name of manga: Bleach
No. of copies: 22
Book borrowed: 13
Author: TiteKubo

Recommended Answers

All 4 Replies

Use the String class. Specifically the split method. Check the String API for that method:

String s = "Bleach,22,13,TiteKubo";
String [] tokens = s.split(",");

//Now print the array and see what happens:
for (int i=0;i<tokens.length;i++) {
  System.out.println(i+": "+tokens[i]);
}

System.out.println("-----");

System.out.println(tokens[0]);
System.out.println(tokens[1]);
System.out.println(tokens[2]);
System.out.println(tokens[3]);

thank you for the help.. ^^.. GOD BLESS

A java program that accepts one string as input

Example Input:
Bleach,22,13,TiteKubo

Output:
Name of manga: Bleach
No. of copies: 22
Book borrowed: 13
Author: TiteKubo

this program must use charAt method.. please help me!..

loop the String and take each character and append it to a new string until you find a ',' character. If the charAt(i) is not ',' concatenate it to a new String, else simply display the string and continue the loop to take the next word.
You might want to make that string empty again in order to add the other characters from the beginning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.