Tuesday, July 7, 2009

intrprog blog july 7,2009

Today, we our hands on exercise. My performance was bad and it is really depressing. I didn't think that it would be so hard that a question would take a lot of time to do. In the end, I had only answered one. And it was wrong. It was so sudden that a lot of hard question were given to us in a short amount of time. I do hope there would still be a chance to recover that 20% I've lost =( .

Friday, July 3, 2009

My first encounters with java

Actually, the first time I met java was only this summer. It was because I saw the flyer that was distributed in our course's pre-confirmation orientation. It was a java short course program held in Lasalle. It was a 5hrs session that last for a week.

Without having any background in java, we were ask to figureout how to swap 3 variables. All of us took alot of time to figure it out. So here's the code that I was able to make.

public class Swapper
{
public static void main (String [] args)
{
int nA=20;
int nB=30;
int nC=0;

System.out.println("Before swapping****");
System.out.println("nA="+nA);
System.out.println("nB="+nB);

/*write your code to swap the values of nA
and nB*/

nC=nA;
nA=nB;
nB=nC;

System.out.println("After swapping****");
System.out.println("nA="+nA);
System.out.println("nB="+nB);
}
}

I forgot the arragements of what we did frst, but here are the things we also did.

1)
public class VariableTester
{
public static void main (String [] args)
{
int nA=20;
double dB=30.03;
String sC="Hello World";
char cD= 'a';

System.out.println( "the variable nA="+nA);
System.out.println( "the variable dB="+dB);
System.out.println( "the variable sC="+sC);
System.out.println( "the variable cD="+cD);
}
}

2)
public class Circle
{
public static void main( String[] args)
{
double dRad= 2.5;
double dPi= 3.1416;
double dCir= 2 * dPi * dRad;

System.out.println("The circumference of a circle given a radius of " + dRad +" is " + dCir);
}
}

3)

public class Matematiks
{
public static void main (String [] args)
{
int nA=5;
int nB=2;
int sumResult=nA+nB;
int difResult=nA-nB;
int prodResult=nA*nB;
int divResult=nA/nB;
int moddivResult=nA%nB;
nA++;
int incResult=nA++;
nB--;
int decResult=nB;

System.out.println("Sum of nA "+
"and nB=" + sumResult);
System.out.println("Difference of nA "+
"and nB=" + difResult);
System.out.println("Product of nA "+
"and nB=" + prodResult);
System.out.println("Division of nA "+
"and nB=" + divResult);
System.out.println("Modulardivision of nA "+
"and nB=" + moddivResult);
System.out.println("Increase of nA "+
"and nB=" + incResult);
System.out.println("Decrease of nA "+
"and nB=" + decResult);


}
}

4)
public class Convert
{
public static void main (String[]args)
{
int nMin=60;
int nHr=5 ;
int nResult= nHr * nMin;
System.out.println("Conversion of nHr "+
"and nMin =" + nResult+ "minutes");
}
}

5)
import java.util.Scanner;
public class GreetMe
{
public static void main(String[]args)
{
Scanner scanKeyBoard = new Scanner(System.in);
System.out.print("Enter your nickname;");
String sUserInput = scanKeyBoard.next();
System.out.println("Hello " + sUserInput + " , Have a Good Day");
}
}

=) .... sharing lang po hehe! first time ko po magprogramming super daming lumabas na error minsan pa nga po 22 errors 0_0 .Kaya nga po nakatulong din sakin ung short corz nung summer.

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.