Anda di halaman 1dari 4

1.

Fill in the blanks in each of the following statements:

a) A left bracket ( { ) begins the body of every method, and a right bracket ( } ) ends the

body of every method.

b) Every statement ends with a semi colon ( ; ).

c) Double slash ( // ) begins an end-of-line comment.

d) Blank lines, space characters, new line characters and are called white space are ignored by
compiler.

e) Java applications begin execution at method main .

f) Methods System.out.print, System.out.println and System.out.printf display information in the


command window.

2. a

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package assignment1b;

/**
*
* @author Benjamin Talic
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

System.out.println("Hello World");
System.out.println("Welcome to Java");
System.out.println("In CS 201");

}
2.b package assignment1b;

/**
*
* @author Benjamin Talic
*/
public class Program2b {

public static void main(String [] args){

System.out.print("Hello World\nWelcome to Java\nIn CS 201");


}

3. package assignment1b;

/**
*
* @author Benjamin Talic
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

int a=20, b=4;


float operation;

operation=a+b; //we add the two numbers;


System.out.println("a+b="+operation);

operation=a-b; //as we alredy printed the sum we can now delete it


//and put the substraction in the same variable to save memory
System.out.println("a-b="+operation);

operation=a/b;
System.out.println("a/b="+operation);

operation=a*b;
System.out.println("a*b="+operation);
}
}
4. package assignment1b;

/**
*
* @author Benjamin Talic
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

//box
System.out.print("*********\n* *\n* *\n* *\n"
+ "* *\n* *\n* *\n* *\n"
+ "*********\n");

//oval
System.out.print(" *** \n * *\n* *\n* *\n"
+ "* *\n* *\n * *\n *** \n");

//arow
System.out.print(" * \n *** \n*****\n *\n *\n *\n *\n *\n *\n");

//diamond
System.out.print(" *\n * *\n * *\n * *\n * *\n * *\n *\n");

1. Edit
We write the program in some text editor or java compiler, correct mistakes
2. Compile
The java compiler translates the java program into bytecodes.
3. Load
In phase 3, the program must first be placed in memory before it can be executed. This is
done by the class loader.
4. Verify
Before the bytecodes in an application are executed by the java interpreter, they are
verified by the bytecode verifier.
5. Execute
the computer, under the control of its CPU, interprets the program one
bytecode at a time. Thus performing the actions specified by the program.

5.
1. structured programming
2. procedure oriented programming
3.object oriented programming

6. Algorithm is a list of steps used to solve a problem.


Pseudocode is a English(or other) based code, not formal syntax but more everyday
commands.

Anda mungkin juga menyukai