11. WAJP, using StringTokenizer class, which reads a
line of integers and then displays each integer and the sum of all integer.
Program:
Download link of Stringtokenizer
Import java.util.stringTokenizer;
class TokenSum
{
public static void main(String[] args)
{
stringTokenizer st=new stringTokenizer(args[0],";");
int sum=0;
while(st.hasMoreElements())
{
int val=Integer.parseInt(st.nextToken());
System.out.println(val+"\t");
sum=sum+val;
}
System.out.println("sum of all no is"+sum);
}
}
Program:
Download link of Stringtokenizer
Import java.util.stringTokenizer;
class TokenSum
{
public static void main(String[] args)
{
stringTokenizer st=new stringTokenizer(args[0],";");
int sum=0;
while(st.hasMoreElements())
{
int val=Integer.parseInt(st.nextToken());
System.out.println(val+"\t");
sum=sum+val;
}
System.out.println("sum of all no is"+sum);
}
}
0 comments:
Post a Comment