TEST PROGRAM TAKEN FROM THE
PREVIOUS LESSONS
REMINDERS IN CREATING A CLASS
Make sure that
your class is inside
of the scr
BASIC OPERATORS AND ESCAPE
SEQUENCEimport java.util.*; //notes this called source file
public class BasicOperators {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
int L = 12;
float W = (float) 35.4;
float A =0;
//find the area of a rectangle
A = L * W;
System.out.println("The area of rectangle is:" +
A);
System.out.println("**************************");
//find the speed
float distance = 3; // 3km.
float time = 2;// 2 hrs.
float Speed;
Speed = distance / time;
System.out.println("The speed is:" + Speed);
System.out.println("**************************");
CONTINUATION:
//calculating my age; example only
int birthyear = 1992;
int presentyear = 2020;
int age;
age = presentyear - birthyear;
System.out.println("My age is :" + age);
System.out.println("***********************");
//calculating of modulus;
//calculating of modulus;
int V = 7,S = 5, m =0;
m = V % S;
System.out.println("The remainder oft" + V +
"tand " + S + "tist" + m); //note I uisng t
escape sequence for tab
OUTPUT:
The area of rectangle is:424.80002
************************************************
The speed is:1.5
************************************************
My age is :28
************************************************
The remainder of 7 and 5 is 2
IDENTIFYING THE PLACE VALUE OF
THE DIGIT
import java.util.*;
public class PlaceValue {
public static void main(String arg[]) {
Scanner Input = new Scanner (System.in);
//Variable Declaration
int num,Thousand,Hundreds,Tens,Ones;
int result1,result2,result3;
System.out.print("Enter number:");
num = Input.nextInt();
System.out.println("There are:");
//calculating the value of thousand
Thousand = num/1000;
System.out.println(Thousand + "Thousands");
//calculating the value of hundreds
result1 = num%1000;
Hundreds = result1/100;
System.out.println(Hundreds + "Hundreds");
//calculating the value of tens
result2 = num%100;
Tens = result2/10;
System.out.println(Tens + "Tens");
IDENTIFYING THE PLACE VALUE OF
THE DIGIT
//calculating the value of ones
result3 = num%10;
Ones = result3/1;
System.out.println(Ones + "Ones");
Input.close();
return ;
}
}
OUTPUT:
Enter number:6785
There are:
6Thousands
7Hundreds
8Tens
5Ones
COMBINATION OF LOGICAL AND
RELATIONAL OPERATORS
OUTPUT:

Test Program - Basic operators

  • 1.
    TEST PROGRAM TAKENFROM THE PREVIOUS LESSONS
  • 2.
    REMINDERS IN CREATINGA CLASS Make sure that your class is inside of the scr
  • 3.
    BASIC OPERATORS ANDESCAPE SEQUENCEimport java.util.*; //notes this called source file public class BasicOperators { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner (System.in); int L = 12; float W = (float) 35.4; float A =0; //find the area of a rectangle A = L * W; System.out.println("The area of rectangle is:" + A); System.out.println("**************************"); //find the speed float distance = 3; // 3km. float time = 2;// 2 hrs. float Speed; Speed = distance / time; System.out.println("The speed is:" + Speed); System.out.println("**************************");
  • 4.
    CONTINUATION: //calculating my age;example only int birthyear = 1992; int presentyear = 2020; int age; age = presentyear - birthyear; System.out.println("My age is :" + age); System.out.println("***********************"); //calculating of modulus; //calculating of modulus; int V = 7,S = 5, m =0; m = V % S; System.out.println("The remainder oft" + V + "tand " + S + "tist" + m); //note I uisng t escape sequence for tab
  • 5.
    OUTPUT: The area ofrectangle is:424.80002 ************************************************ The speed is:1.5 ************************************************ My age is :28 ************************************************ The remainder of 7 and 5 is 2
  • 6.
    IDENTIFYING THE PLACEVALUE OF THE DIGIT import java.util.*; public class PlaceValue { public static void main(String arg[]) { Scanner Input = new Scanner (System.in); //Variable Declaration int num,Thousand,Hundreds,Tens,Ones; int result1,result2,result3; System.out.print("Enter number:"); num = Input.nextInt(); System.out.println("There are:"); //calculating the value of thousand Thousand = num/1000; System.out.println(Thousand + "Thousands"); //calculating the value of hundreds result1 = num%1000; Hundreds = result1/100; System.out.println(Hundreds + "Hundreds"); //calculating the value of tens result2 = num%100; Tens = result2/10; System.out.println(Tens + "Tens");
  • 7.
    IDENTIFYING THE PLACEVALUE OF THE DIGIT //calculating the value of ones result3 = num%10; Ones = result3/1; System.out.println(Ones + "Ones"); Input.close(); return ; } } OUTPUT: Enter number:6785 There are: 6Thousands 7Hundreds 8Tens 5Ones
  • 8.
    COMBINATION OF LOGICALAND RELATIONAL OPERATORS OUTPUT: