查看: 716|回复: 2
|
请大家帮忙(java)
[复制链接]
|
|
发表于 28-1-2007 09:58 PM
|
显示全部楼层
- import java.io.*;
- public class can
- {
-
- public static void main(String [] args) throws IOException
- {
- Student [] studDegree = new Student[5];
-
- for( int i = 0; i < studDegree.length; i++ )
- {
- studDegree[i] = new Student(i);
- }
-
- System.out.println("");
- System.out.println("Candidates\tVotes Received\t% of Total Votes");
-
- for ( int i = 0; i < studDegree.length; i++ )
- {
- studDegree[i].printInfo();
- }
- System.out.println(" Jumlah\t " + Student.total);
- System.out.println(" Pemenang ialah " + studDegree[Student.winner].candidate);
- }
-
- }
- class Student
- {
- String candidate;
- int vote;
- double percentage;
- static int total = 0;
- static int max = 0;
- static int winner;
-
- public Student(int i) throws IOException
- {
- InputStreamReader read = new InputStreamReader(System.in);
- BufferedReader input = new BufferedReader(read);
-
- System.out.print("Candidate: ");
- candidate = input.readLine();
- System.out.print("Votes Receive: ");
- vote = Integer.parseInt(input.readLine());
- total += vote;
- if ( vote > max )
- {
- max = vote;
- winner = i;
- }
- }
-
- public void printInfo()
- {
- percentage = (double) vote / total * 100;
- System.out.printf(" %-12s\t %-6d\t %.2f\n", candidate, vote, percentage);
- }
-
- }
复制代码 |
|
|
|
|
|
|
|

楼主 |
发表于 28-1-2007 11:31 PM
|
显示全部楼层
原帖由 MaokeJackson 于 28-1-2007 09:58 PM 发表
import java.io.*;
public class can
{
public static void main(String [] args) throws IOException
{
Student ;
for( int i = 0; i < studDegree.lengt ...
你真的好厉害。。。。如果我像你就好。。。。你真的是我的大恩人。。。。谢谢你
小妹我感激不尽。。。。。。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|