Ameya 2
Ameya 2
Ameya 2
⑲
Name: Ameya
Nikhil Kalgutkar
Kadam Grade :
Class/Roll No.:
D6ADA/26
&27
Aim: A) Printing Fibonacci Series up to the nth term taking the value of n
from the user.
Theory :
▪ Java provides different ways to get input from the user.
▪ In order to use the object of Scanner, we need to import java.util.Scanner package.
import java.util.Scanner;
▪ Then, we need to create an object of the Scanner class. We can use the object to take input
from the user.
▪ Syntax:
Scanner input = new Scanner(System.in);
Import java.util.Scanner;
Class FibonacciSeries {
Public static void main(String[] arg ){
Scanner scanner = new Scanner(System.in);
Output
Screenshots :
Conclusion: Upon running the program, the user is prompted to enter the
value of 'n', representing the number of terms in the Fibonacci series. The
program then generates and prints the series up to the nth term. Students
will observe the sequence's growth and understand how objectoriented
programming can be applied to solve real-world mathematical problems.
Artificial Intelligence and Data Science Department
Theory :
1. A Function in Java is a block of statements that is defined to perform a
specific task. A function is also called a reusable code because once it is
created, it can be used again and again.
In Java, there are two categories of functions available, and they are:
• Built-in Functions : These functions are predefined, and we can use them
any time we want in our Java program. For example pow(), sqrt(), min(), etc.
• User Defined Functions : These functions are defined or created by the
programmer for performing a specific task in a program.
2. The static keyword is used to construct methods that will exist regardless of
whether or not any instances of the class are generated. Any method that
uses the static keyword is referred to as a static method.
Program :
import java.util.Scanner;
class NumberReverse {
int number;
public NumberReverse(int num) {
number = num;
}
public int reverseNumber() {
int reversed = 0;
while (number != 0) {
int digit = number % 10;
reversed = reversed*10 +digit number /= 10;
}
return reversed;
}
2. Output Screenshots :
Aim: C) WAP to read the numbers & shift left & right by 3 bits
Theory:
The right shift operator shifts the bits towards the right by the specified number of times. It is denoted
by the symbol >>.
When a bit is shifted towards the right, the rightmost bit (least significant bit) is discarded and the
leftmost bit (most significant) bit is filled with the sign bit (i.e.) when the number is positive, 0 is used to
fill the leftmost position, and when the number is negative, the sign bit is used to fill the leftmost
position.
Program:
Import java.util.Scanner;
Output:
Conclusion: The right shift operator in Java moves the bits of a value towards the right by the specified
number of bits. In the signed right shift, the rightmost bit is discarded, and the leftmost bit is filled with
the sign bit.