Unit 1_ OOP in Java
Introduction_3
Tutor: Ruvinga
Contents
• Java Program to read integer value from the Standard Input(data
type)
• Java Program to check if Number is Positive or Negative(IF Else)
• Java Program to Add two Numbers
Java Program to read integer value from the Standard Input
• this program reads an integer number entered by user.
• Scanner class is in [Link] package used for capturing the input of
the primitive types like int, double etc. and strings.
• import the package [Link] to use Scanner.
• In order to read the input provided by user, we first create the object
of Scanner by passing [Link] as parameter.
• Then we use nextInt() method of Scanner class to read the integer. I
Java Program to check if Number is Positive or Negative
• There are two java programs
1. checks whether the specified number is positive or negative.
2. takes the input number (entered by user) and checks whether it is
positive or negative and displays the result.
To understand this program you should have the basic knowledge of
if-else-if statement
Algorithm
1. If a number is greater than zero then it is a positive number
2. If a number is less than zero then it is a negative number
3. If a number is equal to zero then it is neither negative nor positive.
Check whether the input number(entered by user) is positive or
negative
Java Program to Add two Numbers
There are two programs to add two numbers,
[Link] the value of both the numbers in the program itself.
2. takes both the numbers (entered by user) and prints the sum.
Lab Exercises to be recorded in your Lab
report under Unit 1 Lab exercises
• Java Program to print Odd numbers from 1 to n or 1 to 100
• Java program for bubble sort in Ascending & descending order
• Java Program to read integer value from the Standard Input
• Java Program to Print alternate Prime numbers
• Java program to Print Armstrong numbers between a given range
• Java Program to check Vowel or Consonant using Switch Case