I am a very new java student.I need to write a program ask the users to enter the series numbers separated by commas, with the valid input is : 23,45,90,4,5
The program should calculate and display the sume of all the numbers.
I had written the code. I knew it is not a good code but I did not know undertand much about String ...Could someone please help? Thanks much.
My first class code is :
import java.util.StringTokenizer;
public class ClassNumber
{
private String series;
// The construc accepts a string containning series
public ClassNumber(String numberStr)
{
// Create a StringTokenizer object.
StringTokenizer strTokenizer = new StringTokenizer(numberStr,"/");
series = strTokenizer.nextToken();
}
// getSeries method returns the month field.
public String getSeries()
{
return series;
}
}
public class TestClassNumber
{
public static void main (String[] args)
{
// create a string contataing series numbers
String series = "23,45,90,4,5";
TestClassNumber sr = new TestClassNumber (series);
//Display the component of the series
System.out.println(" Input a series of numbers separated by commas:" + series);
}
}