[go: up one dir, main page]

0% found this document useful (0 votes)
4 views6 pages

Scanner and Methods

Uploaded by

pratikshagite382
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Scanner and Methods

Uploaded by

pratikshagite382
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Scanner Class

Scanner is a class in java.util package.


used for obtaining the input of the primitive types.

Syntax to define use Scanner class


Scanner sc = new Scanner(System.in);

nextByte() byte value from the user


nextDouble() double value from the user
nextFloat() float value from the user
nextInt() int value from the user
nextLine() / next() String value from the user
nextLine().charAt(0) /next().charAt(0) char value from the user
nextLong() long value from the user
nextBoolean() boolean value from user
nextShort() short value from the user
Method in Java
A Java method is a collection of statements that are grouped together to perform an operation.
Types Of Method

• Static Method
• Instance Method/ NonStatic method
• Parameterized
• Accessor/Getter Method
• Mutator/Setter Method
• Recursive Method

Static Method
Static methods are the methods in java that are called without object.

public static void main(String [] args)

Instance Method
The method of the class is known as an instance method. It is a non-static method defined in the class and it is
called using object.
public void display()
Parameterized Method
Method having parameters or arguments are called parameterized method.
public int Addition(int a, int b)

Accessor/Getter Method
The method that reads the instance variable is known as the accessor method.
public int getId()
{
return Id;
}

Mutator/Setter Method
The method(s) read the instance variable(s) and also modify the values.
public void setRoll(int roll)
{
this.roll = roll;
}
• Recursive Method
• Recursion is the technique of function making call itself.
• Halting Condition
static void fun()
{
fun();
}
p.s.v.m(String args[])
{
fun();
}
So, to avoid this we need halting condition
int cnt=0;
static void fun()
{
cnt++;
if(cnt<=3)
{
fun();
}
}
p.s.v.m(String args[])
{
fun();
}
• Halting Condition
Infinite recursion is the function never stop calling itself, it will goes in the infinite state.
To stop the problem of infinite recursion we used halting condition

You might also like