Вы находитесь на странице: 1из 9

S. M.

Rakibul Hasan
ID: 14CSE070400
Problem No: 3.1
Problem Specification: A simple Java program.
Description of the problem: This program is perhaps the simplest of all java programs.
This program contains class, Opening Brace, Main method, println method, Ending
Brace.
Psedo Code:

class SampleOne
{
public static void main(String args[])
{
System.out.println("Java is better than C++.");
}
}

Problem No: 3.2


Problem Specification: a java program with multiple statements.
Description of the problem: this java program is a simple java program. But it has more
number of statements and in this program we use math Function.
Psedo Code:

import java.lang.Math;
class SquareRoot
{
public static void main(String args[])
{
double x = 5, y;
y = Math.sqrt(x);
System.out.println("y = " + y);
}
}

Problem No: 3.3


Problem Specification: A program with multiple classes.
Description of the problem: This program defines two classes Room and RoomArea.
The Room class defines two variables and one method to assign value to these variables.
The class RoomArea contains the main method that initiates the execution. We use the
getdata method to assigns values to the data members of Room class.
Psedo Code:

class Room
{
S. M. Rakibul Hasan
ID: 14CSE070400
float length, breadth;

void getdata(float a, float b)


{
length = a;
breadth = b;
}
}

class RoomArea
{
public static void main(String args[])
{
float area;
Room room1 = new Room();
room1.getdata(14, 10);
area = room1.length * room1.breadth;
System.out.println("Area = " + area);
}
}

Problem No: 3.4


Problem Specification: A simple program for testing.
Description of the problem: The file name must be the classname of the class
containing the main method.
Psedo Code:

class Test
{
public static void main(String args[])
{
System.out.println("Hello");
System.out.println("Welcome to the world of Java");
System.out.println("Let us learn Java.");

}
}

Problem No: 3.5


Problem Specification: Write a java program use of command line arguments.
S. M. Rakibul Hasan
ID: 14CSE070400
Description of the problem: This program illustrates the use of command line
arguments.
Psedo Code:

/* This program uses command line


arguments as input.*/
class ComLineTest
{
public static void main(String args[])
{
int count, i=0;
String string;
count = args.length;
System.out.println("Number of arguments = " + count);
while(i< count)
{
string = args[i];
i= i+1;
System.out.println(i+ " : " + "Java is " +string+ "!");
}
}
}

Problem No: 4.1


Problem Specification: Reading data from keyboard.
Description of the problem: The readLine( ) method reads the input from the keyboard
as a string which is then converted to the integer data type using the data type wrapper
class. We have used the keyword try and catch to handle any errors that might occur
during the reading process.
Psedo Code:

import java.io.*;

class Reading
{
public static void main(String args[])
{
DataInputStream in = new DataInputStream(System.in);

int n=0;
float f=0.0F;
String s="";
S. M. Rakibul Hasan
ID: 14CSE070400
try
{

System.out.println("Enter an integer");
n=Integer.parseInt(in.readLine());
System.out.println("Enter a float");
f=Float.parseFloat(in.readLine());
System.out.println("Enter a string");
InputStreamReader b = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(b);
s=br.readLine();
}

catch(Exception e)
{
System.out.println("I/O Error");
}

System.out.println("The integer number is : " + n);


System.out.println("The float number is : " + f);
System.out.println("The String is : " + s);
}
}

Problem No: 4.2


Problem Specification: Creation and casting of variables.
Description of the problem: This is a simple java program which is the creation and
casting of variable.
Psedo Code:

class TypeWrap
{
public static void main(String args[])
{
System.out.println("Variables created");
char c = 'X';
byte b = 50;
short s = 1996;
int i = 123456789;
long l = 1234567654321L;
float f1 = 3.142F;
float f2 = 1.2e-5F;
double d2 = 0.000000987;
S. M. Rakibul Hasan
ID: 14CSE070400
System.out.println(" c = " + c);
System.out.println(" b = " + b);
System.out.println(" s = " + s);
System.out.println(" i = " + i);
System.out.println(" l = " + l);
System.out.println(" f1 = " + f1);
System.out.println(" f2 = " + f2);
System.out.println(" d2 = " + d2);

System.out.println("");
System.out.println("Types converted");

short s1 = (short)b;
short s2 = (short)i;
float n1 = (float)l;
int m1 = (int)f1;

System.out.println(" (short)b = " + s1);


System.out.println(" (short)i = " + s2);
System.out.println(" (float)l = " + n1);
System.out.println(" (int)f1 = " + m1);
}
}

Problem No: 4.3


Problem Specification: Getting the result to the screen.
Description of the problem: This program illustrates the behavior of print() and println()
method.
Psedo Code:

class Displaying
{
public static void main(String args[])
{
System.out.println("Screen Diplay");
for(int i =1; i<=9; i++)
{
for(int j = 1; j<= i;j++)
{
System.out.print(" ");
System.out.print(i);
}
System.out.print("\n");
S. M. Rakibul Hasan
ID: 14CSE070400
}
System.out.println("Screen Display Done");
}
}

Problem No: 5.1


Problem Specification: Floating point arithmetic.
Description of the problem: A real operand may assume values either in decimal or
exponential notation. Since floating point values are rounded to the number of significant
digits permissible, the final value is an approximation the correct result.
Psedo Code:

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

float a=20.5F, b=6.4F;

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


System.out.println(" b = " +b);
System.out.println(" a+b = " +(a+b));
System.out.println(" a-b = " +(a-b));
System.out.println(" a*b = " +(a*b));
System.out.println(" a/b = " +(a/b));
System.out.println(" a%b = " +(a%b));
}
}

Problem No: 5.2


Problem Specification: Implementation of relational operators.
Description of the problem: this is a java program which are illustrates Relational
expression. These are used in decision statement.
Psedo Code:

class RelationalOperators
{
public static void main(String args[])
{
S. M. Rakibul Hasan
ID: 14CSE070400

float a=15.0F, b=20.75F, c=15.0F;

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


System.out.println(" b = " +b);
System.out.println(" c = " +c);
System.out.println(" a<b is " +(a<b));
System.out.println(" a>b is " +(a>b));
System.out.println(" a==c is " +(a==c));
System.out.println(" a<=c is " +(a<=c));
System.out.println(" a>=b is " +(a>=b));
System.out.println(" b!=c is " +(b!=c));
System.out.println(" b==a+c is " +(b==a+c));
}
}

Problem No: 5.3


Problem Specification: Increment operator illustrated.
Description of the problem: In this program we fallow the work of increment operator.
Psedo Code:

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

int m=10, n=20;

System.out.println(" m = " +m);


System.out.println(" n = " +n);
System.out.println(" ++m = " + ++m);
System.out.println(" n++ = " + n++);
System.out.println(" m = " + m);
System.out.println(" n = " + n);

}
}
S. M. Rakibul Hasan
ID: 14CSE070400
Problem No: 5.4
Problem Specification: Illustration of the use of casting operation.
Description of the problem: This is a simple java program which are illustrates use
casting operation.
Psedo Code:

class Casting
{
public static void main(String args[])
{
int i;
float sum;
sum=0.0F;
for(i=1;i<=10;i++)
{
sum = sum + 1/(float)i;
System.out.print(" i = " + i);
System.out.println(" sum = " + sum);
}
}
}

Problem No: 5.5


Problem Specification: Demonstration of Java expressions.
Description of the problem: Here we used various kind of operator.
Psedo Code:

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

//Declaration and Initialization


int a=10, b=5, c=8, d=2;
float x=6.4F, y=3.0F;

//Order of Evaluation
int answer1 = a * b + c / d;
int answer2 = a * (b + c) / d;

//Type Conversions
float answer3 = a / c;
float answer4 = (float)a / c;
float answer5 = a / y;
S. M. Rakibul Hasan
ID: 14CSE070400

//Modulo Operations
int answer6 = a % c;
float answer7 = x % y;

//Logical Operations
boolean bool1 = a > b && c > d;
boolean bool2 = a < b && c > d;
boolean bool3 = a < b || c > d;
boolean bool4 = !(a-b == c);

System.out.println("Order of Evaluation");
System.out.println(" a * b + c / d = " + answer1);
System.out.println(" a * (b + c) / d = " + answer2);

System.out.println("Type Conversion");
System.out.println(" a / c = " + answer3);
System.out.println(" (float)a / c = " + answer4);
System.out.println(" a / y = " + answer5);

System.out.println("Modulo Operation");
System.out.println(" a % c = " + answer6);
System.out.println(" x % y = " + answer7);

System.out.println("Logical Operations");
System.out.println(" a > b && c > d = " + bool1);
System.out.println(" a < b && c > d = " + bool2);
System.out.println(" a < b || c > d = " + bool3);
System.out.println(" !(a-b == c) = " + bool4);

}
}