Friday, July 3, 2009

Using replace ; replaceFirst ; replaceAll

I would like to share the programs i did in the intprog on july,2,2009.
So here it is:

The Censor activity
import java.util.Scanner;
public class Aa
{
public static void main(String [] args)
{
System.out.println("Enter your string");
Scanner a= new Scanner(System.in);
String z=a.nextLine();
String letter=z.replaceAll("ateneo", "****");
System.out.println(letter);
}
}
While I was in the lab, I also tried applying the replaceFirst method and because of that I learned how to use the backslash quotation mark from our prof, thanks sir! I didn't think that it was possible to write a quatation mark within a string.

import java.util.Scanner;
public class ReplaceFirst
{
public static void main(String [] args)
{
System.out.println("Type \"i love lasalle\"");
System.out.println("Enter your sentence");
Scanner a= new Scanner(System.in);
String z=a.nextLine();
String letter=z.replaceFirst("i","You");
System.out.println(letter);
}
}

After doing the replaceFirst, i decided to do the replace, but unfortunately i wasn't able to save it. So this is the code that i think i did, i don't know if it's correct because I still haven't downloaded the jcreator.

import java.util.Scanner;
public class Replace
{
public static void main(String [] args)
{
System.out.println("I'll change all \"i \" you enter into \" a\"");
System.out.println("Enter your sentence");
Scanner a= new Scanner(System.in);
String z=a.nextLine();
String letter=z.replace("i","a");
System.out.println(letter);
}
}

Aside using the replaceAll, we were asked to use the PolygonVisualizer. Unfortunately, i didn't get it. I starting to think that the lessons are getting harder for me. =<

//sir pasensya na lng ung sa tabs yaw mag work d2 sa syt e.

1 comment:

  1. Ok lang yan, pag hindi challenging nakakaantok e hehe :) {1 ORP} for you :)

    ReplyDelete