-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListEvenOdd.java
More file actions
54 lines (51 loc) · 1.31 KB
/
LinkedListEvenOdd.java
File metadata and controls
54 lines (51 loc) · 1.31 KB
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
package Codes;
import java.util.Scanner;
public class LinkedListEvenOdd {
Node head;
static class Node{
int data;
Node next;
Node(int d){
data=d;
next=null;
}
}
static void append(LinkedListEvenOdd list, int d){
Node newnode=new Node(d);
if (list.head==null)
list.head=newnode;
else {
Node ref=list.head;
while (ref.next!=null){
ref=ref.next;
}
ref.next=newnode;
}
}
static String result(LinkedListEvenOdd list){
Node temp=list.head;
int count=0, sum=0, avg=0;
while (temp!=null){
sum=sum+temp.data;
count++;
temp=temp.next;
}
// System.out.println(count);
avg=sum/count;
if (avg%2==0)
return "EVEN";
else
return "ODD";
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
LinkedListEvenOdd list = new LinkedListEvenOdd();
String element=sc.nextLine();
String[] input=element.split(" ");
for (String s : input) {
int value = Integer.parseInt(s);
append(list, value);
}
System.out.println(result(list));
}
}