forked from sourabh48/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvote.java
More file actions
95 lines (57 loc) · 1.71 KB
/
vote.java
File metadata and controls
95 lines (57 loc) · 1.71 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.io.*;
public class vote
{
public static void main(String args[])
{
int win=1,loose=1,waste=0,poll=0,i=0;
DataInputStream dis=new DataInputStream(System.in);
try
{
/*Input conditions*/
System.out.println("\n\nWELCOME TO ELECTION SOFTWARE 1.1.....\n\n");
System.out.println("Enter the number of voters:\n");
int voters=Integer.parseInt(dis.readLine());
System.out.println("Enter the number of candidates:\n");
int n=Integer.parseInt(dis.readLine());
int candidate[]=new int[n+1];
loop: for( i=1;i<=voters;i++)
{
System.out.println("Enter the sl no of candidate you support or else press 0:\n");
poll=Integer.parseInt(dis.readLine());
if (poll<1 && poll>(n))
{
waste=waste+1;
continue loop;
}
else
{
candidate[poll]=candidate[poll]+1;
}
}
System.out.println("\n\nVOTING RESULT BY VOTE 1.1...\n\n");
for( i=1;i<=n;i++)
{
System.out.println("The Candidate of I.D.: "+(i)+" has received " +candidate[i]+" votes");
}
for( i=1;i<=(n-1);i++)
{
for(int j=(i+1);j<=(n-1);j++)
{
if(candidate[i]>candidate[j])
{
loose=j;
}
else if(candidate[i]<candidate[j])
{
win=j;
}
}
}
System.out.println("\n\nDECLARATION OF WINNER \n");
System.out.println("winner is "+win+ "received "+candidate[win]+" votes");
System.out.println("looser is "+loose+"received "+candidate[loose]+" votes");
}
catch(Exception e)
{}
}
}