MIT11053 Chapter 02 2023
MIT11053 Chapter 02 2023
• Statements
• Variables
• Data Types
• Arithmetic Calculations
• Taking Input from User
int othrs=5;
System.out.println("netsalary= "+netsal);
quantity
int x; // Declare x to be an
// integer variable;
double radius; // Declare radius to
// be a double variable;
char a; // Declare a to be a
// character variable;
int x, y, z;
String firstName, lastName;
int myAge;
myAge = 43;
String myName;
myName = “SaNa";
int age;
float $money;
char my_char;
long _no;
String name7;
A Variable Name should start with an
Alphabetical letter or $, or _ symbol
The other characters can include numbers
But you cannot use symbols like @, #, etc
MIT11053 by Prof. S.Sabraz Nawaz 16
Variable Names
int my age;
float @money;
char 6my_char;
long no*;
int qty;
String firstName;
float basicSal, netSal;
+ Addition 34 + 1 35
% Remainder 20 % 3 2
String is actually a predefined class in the Java library just like the
System class. The String type is not a primitive type. It is known
as a reference type. Any Java class can be used as a reference type
for a variable.
String nextLine() Returns the rest of the current line, excluding any line
separator at the end.
01
02
03
Implicit casting
double d = 3; (type widening)
Explicit casting
int i = (int)3.0; (type narrowing)
int i = (int)3.9; (Fraction part is
truncated)
range increases
1. Write a Java program that takes three marks of an exam and displays the
total and the average.
2. Write a program to input how many notes, coins of denominations of
1000/=, 500/=, 200/=, 100/= 50/=,20/=,10/=,5/=, 2/= and 1/= are
available. Print the total amount