Thursday, June 4, 2009

Java Basics Using Qt Jambi Tutorial

  1. Branching Statements

    1. break; - The break statement terminates the loop.

    2. continue; - when reached, it goes to the loop statement and evaluates the condition.

Ex. for (x=0; x<10;x++){

if (x==4){

continue;

}

System.out.println(x);

}

//this code prints from 0 to 3 and skips 4 and prints 5 to 9.

    1. return;

Ex.

import java.lang.*;


public class AddNumbers{

public int add(int x,int y){

return x + y; //passes 1 and 2 then adds them and return the result

}

public static void main(String[] args){

boolean addnum = true;

AddNumbers num = new AddNumbers();

while (addnum){

System.out.println(num.add(1,2)); //passes 1 and 2 to add method and prints the result.

addnum = false;

}

}

}

to be continued...

No comments: