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.
Friday, July 3, 2009
Subscribe to:
Post Comments (Atom)
I see. That's good. I hope that through our lessons you also get to clarify the questions you had before during the short course :) {1 ORP} for you :)
ReplyDeleteyup, madami pa rin nga po ako natutunan sa lessons natn. learning has no limits hehe =p
ReplyDelete