Java Program to Convert the given Word in a file to Caps | IT2305 - Java Programming Lab


AIM:
 To write a Java program to Convert the given word in a file to Capital Letters in IT2305 - Java Programming Laboratory.

SOURCE CODE:
import static java.lang.System.*;
import java.io.*;
import java.util.*;
public class File1
{       
        public static void main(String args[]) throws IOException
        {
                String s,s1;
                int i;
                File f1=new File("hai.java");
                File f2=new File("hello.java");
                Scanner sin=new Scanner(f1);
                PrintWriter pw=new PrintWriter(f2);
                StringTokenizer st;
                while(true)
                {
                        if(sin.hasNext())
                        {
                                s=sin.nextLine();
                                st=new StringTokenizer(s," ",true);
                                while(st.hasMoreTokens())
                                {
                                s1=st.nextToken();
      for(i=0;i<args.length;i++)
                                {
                                        if(s1.compareTo(args[i])==0)
                                        {
                                                pw.print(s1.toUpperCase());
                                                i=10;
                                                break;
                                        }
                                }
                                if(i!=10)
                                {
                                        pw.print(s1);
                                }
                                }
                                pw.print(" ");
                                i=0;
                        }
                        else
                                break;
                        pw.print("\n");
                }
                  pw.close();
                  sin.close();
      }
}
Previous
Next Post »

Still not found what you are looking for? Try again here.