Java Week2(C) Notepad

636 views

Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Java Week2(C) Notepad

  1. 1. JAVA WEEK2(C) /* Week 2 : c) Write a Java Program that reads a line of integers, and then displays each integer, and the sum of all the integers (Use StringTokenizer class of java.util) */ import javax.swing.*; import java.util.*; import java.io.*; public class LabPro7 { public static void main(String args[])throws IOException { int sum=0; String line=JOptionPane.showInputDialog("enter the line"); String k=JOptionPane.showInputDialog("enter the delemeter"); StringTokenizer wd=new StringTokenizer(line,k); while(wd.hasMoreTokens()) sum=sum+Integer.parseInt(wd.nextToken()); JOptionPane.showMessageDialog(null,"sum is"+sum); } } Page 1

×