0

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

Edited by loveu: n/a

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by javaAddict
1

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]);
0

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!..

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.