| | |
hey guys i need help to
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2007
Posts: 4
Reputation:
Solved Threads: 0
1 import java.util.*;
2 publicclass CALC
3 {
4 publicstaticvoid main (String[] args)
5 { int much;
6 System.out.print("\nEnter the number of numbers ");
7 Scanner input=new Scanner(System.in);
8 much=input.nextInt();
9
10
11 int[]num=newint[much];
12 double[]perc=newdouble[num.length];
13
14 int[]den=newint[num.length];
15 int total=0;
16 int total1=0;
17 int perhold,smal;
18 double smallest,highest;
19 double percent;
20 int perc1;
21 int count=0;
22 double average;
23 for(int i=0;i<=num.length-1;i++)
24 {
25 System.out.print("Enter top number "+(i+1)+ " ");
26 num[i]=input.nextInt();
27 System.out.print("Enter the bottom number"+(i+1)+" ");
28 den[i]=input.nextInt();
29
30 perc[i]=(double)num[i]/(double)den[i];
31 perc[i]=perc[i]*100;
32 perc[i]=perc[i]+0.5;
33 perhold=(int)perc[i];
34 }
35
36 total=totalfind(num);
37 total1=totalfind(den);
38 average=(double)total/(double) total1;
39 percent=average*100.00;
40 percent=percent+0.5;
41 perc1=(int)percent;
42 System.out.print(" \n Grade percent average is "+ perc1+"%");
43
44 smallest=smallfind(perc); //here is the problem
45
46
47 System.out.print("\nthe smallest percent= " + smallest);
48
49
50
51
52 }//end main metod
53 publicstaticint totalfind(int[] number)
54 {
55 int tempt;
56 int tat=0;
57 for(int i=0;i<=number.length-1;i++)
58
59 tat=tat+number[i];
60 tempt=tat;
61 return tempt;
62 }
63 publicstaticint total2find(int[]dem1)
64 {
65 int tempt;
66 int tat2=0;
67 for(int i=0;i<=dem1.length-1;i++)
68 tat2=tat2+dem1[i];
69 tempt=tat2;
70 return tempt;
71 }
72
73 publicstaticint smallfind(int[]small)
74 {
75
76 int temp;
77 int index=0;
78 temp=small[0];
79 for(int i=1;i<=small.length-1;i++)
80 if(small[i]<temp)
81 {
82 temp=small[i];
83 index=i;
84 }
85 return index; //return the position of the smallest
86 }
87
88 //i supposed to find the average score percentage and lowest and highest percentage,
89
90
91
92
93
94
95
96
97
98 }
2 publicclass CALC
3 {
4 publicstaticvoid main (String[] args)
5 { int much;
6 System.out.print("\nEnter the number of numbers ");
7 Scanner input=new Scanner(System.in);
8 much=input.nextInt();
9
10
11 int[]num=newint[much];
12 double[]perc=newdouble[num.length];
13
14 int[]den=newint[num.length];
15 int total=0;
16 int total1=0;
17 int perhold,smal;
18 double smallest,highest;
19 double percent;
20 int perc1;
21 int count=0;
22 double average;
23 for(int i=0;i<=num.length-1;i++)
24 {
25 System.out.print("Enter top number "+(i+1)+ " ");
26 num[i]=input.nextInt();
27 System.out.print("Enter the bottom number"+(i+1)+" ");
28 den[i]=input.nextInt();
29
30 perc[i]=(double)num[i]/(double)den[i];
31 perc[i]=perc[i]*100;
32 perc[i]=perc[i]+0.5;
33 perhold=(int)perc[i];
34 }
35
36 total=totalfind(num);
37 total1=totalfind(den);
38 average=(double)total/(double) total1;
39 percent=average*100.00;
40 percent=percent+0.5;
41 perc1=(int)percent;
42 System.out.print(" \n Grade percent average is "+ perc1+"%");
43
44 smallest=smallfind(perc); //here is the problem
45
46
47 System.out.print("\nthe smallest percent= " + smallest);
48
49
50
51
52 }//end main metod
53 publicstaticint totalfind(int[] number)
54 {
55 int tempt;
56 int tat=0;
57 for(int i=0;i<=number.length-1;i++)
58
59 tat=tat+number[i];
60 tempt=tat;
61 return tempt;
62 }
63 publicstaticint total2find(int[]dem1)
64 {
65 int tempt;
66 int tat2=0;
67 for(int i=0;i<=dem1.length-1;i++)
68 tat2=tat2+dem1[i];
69 tempt=tat2;
70 return tempt;
71 }
72
73 publicstaticint smallfind(int[]small)
74 {
75
76 int temp;
77 int index=0;
78 temp=small[0];
79 for(int i=1;i<=small.length-1;i++)
80 if(small[i]<temp)
81 {
82 temp=small[i];
83 index=i;
84 }
85 return index; //return the position of the smallest
86 }
87
88 //i supposed to find the average score percentage and lowest and highest percentage,
89
90
91
92
93
94
95
96
97
98 }
First thing first, when you copy and paste code can you please use tag for inserting code into post, which is the hash "#" sign on the toolbar for creating post. Thank you
Secondly please follow JAVA coding standarts, there are not there just for fun
Fourth method smallfind is supposed to return the smallest percantage in your array, that is what you expect on line 44, in reality however you sending index position in the array not actual value from that position(line 83 assign array position to index, line 85 return this value)
Secondly please follow JAVA coding standarts, there are not there just for fun
- class naming CALC should be Calc or if you wish MyCalculationProgram
- methods totalfind should be totalFind
Fourth method smallfind is supposed to return the smallest percantage in your array, that is what you expect on line 44, in reality however you sending index position in the array not actual value from that position(line 83 assign array position to index, line 85 return this value)
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- You Guys Play Videogames? (Geeks' Lounge)
- Hey Guys, CMS needed ..... (Existing Scripts)
- hard drive Issue....Help :( (Storage)
- Hey guys can anybody help me (Geeks' Lounge)
- hey guys; having some trouble with this program i'm writing (Java)
Other Threads in the Java Forum
- Previous Thread: Problem in Timer thread
- Next Thread: help needed badly
Views: 1000 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool keyword linux list loop map method methods mobile netbeans newbie number object oracle pong print problem producer program programming project projectideas read recursion reflection rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows





