Sabtu, 26 September 2009

Method dalam Java

public class Hello {
static {
System.out.println("Boby Hendrik");
}
public static void main(String[] args) // Contoh statement method
{
Hello Hello=new Hello();
System.out.println("Berapa nomor NPM kamu :");
Hello=new Hello();
System.out.println("10107352");
}
}

class dalam java

import java.awt.*;
import java.applet.*;

public class boby extends Applet {

public void init() {
}

public void paint(Graphics g) {

g.drawString("boby hendrik", 50, 60 );
g.drawString("10107352", 50, 80 );
g.drawString("3KA16", 50, 100 );

}
}

class continue java

class ContinueDemo {
public static void main(String[] args) {

String searchMe = "peter piper picked a peck of pickled peppers";
int max = searchMe.length();
int numPs = 0;

for (int i = 0; i < max; i++) {
//interested only in p's
if (searchMe.charAt(i) != 'p')
continue;

//process p's
numPs++;
}
System.out.println("Found " + numPs + " p's in the string.");
}
}

class break java

class BreakDemo {
public static void main(String[] args) {

int[] arrayOfInts = { 32, 87, 3, 589, 12, 1076,
2000, 8, 622, 127 };
int searchfor = 12;

int i;
boolean foundIt = false;

for (i = 0; i < arrayOfInts.length; i++) {
if (arrayOfInts[i] == searchfor) {
foundIt = true;
break;
}
}

if (foundIt) {
System.out.println("Found " + searchfor
+ " at index " + i);
} else {
System.out.println(searchfor
+ " not in the array");
}
}
}
public class Hello {
static {
System.out.println("boby hendrik");
}
public static void main(String[] args) // Contoh statement method
{
Hello Hello=new Hello();
System.out.println("Berapa nomor NPM kamu :");
Hello=new Hello();
System.out.println("10107352");
}
}
import java.awt.*;
import java.applet.*;

public class boby extends Applet {

public void init() {
}

public void paint(Graphics g) {

g.drawString("boby hendrik", 50, 60 );
g.drawString("10107352", 50, 80 );
g.drawString("3KA16", 50, 100 );

}
}