-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssignment1.java
56 lines (54 loc) · 1.43 KB
/
Assignment1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author hrupa
*/
import java.util.*;
public class Assignment1 {
int a,b,n_evenodd,n_fact,n_fibo;
void input(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter two numbers for addition");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("Enter a number to check even/odd");
n_evenodd=sc.nextInt();
System.out.println("Enter a number to find factorial");
n_fact=sc.nextInt();
System.out.println("Enter the range of fibonacci series");
n_fibo=sc.nextInt();
}
int addTwoNumbers(){
return a+b;
}
int factorial(){
int f=1;
for(int i=1;i<=n_fact;i++)
f=f*i;
return f;
}
void evenOdd(){
if(n_evenodd%2==0)
System.out.println(n_evenodd+" is even");
else
System.out.println(n_evenodd+" is odd");
}
void fibonacci(){
int a=0,b=1;
int c;
System.out.print("Fibonacci series is ");
System.out.print(a+","+b+",");
for(int i=3;i<=n_fibo;i++){
c=a+b;
a=b;b=c;
if(i!=n_fibo)
System.out.print(c+",");
else
System.out.print(c);
}
}
}