Results 1 to 6 of 6
- 02-28-2009, 09:35 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
why my coding cannot give the correct answer?
somebody help me please..here my coding
import java.util.Scanner;
public class SumNumbers4 {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("How many number?");
int numNumber = scanner.nextInt();
int data = 0;
int max = data;
int min = data;
int sum = 0;
for(int i = 1;i<= numNumber ; i++) {
System.out.println("Please input number" + i + ":");
int number = scanner.nextInt();
sum += number;
}
System.out.println("Sum of the number is" + sum);
double average = sum/numNumber;
System.out.println(" The average is" + average);
if (data> max){
max = data;
}
else if (data < min){
min = data;
}
else if (data >= 0 & data < max){
min = data;
}
else if (data<= 0 & data> min){
max = data;
}
System.out.println("The largest number is" + max);
System.out.println("The smallest number is" + min);
}
}
:(
-
Thanks for posting that. That's some really nice code.
- 02-28-2009, 02:39 PM #3
hhhmmm...
Remember... the most information you can provide will result in better and more accurate help. Just posting code and saying "code is giving wrong output" does not help diagnose the problem with your code. Imagine taking your car to the mechanics and saying "it doesn't work". How is he going to fix the car with that information?
I magine your output is zero for both min & max. That is because they were initially assigned zero and never were given any other value (check your code).
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-28-2009, 04:20 PM #4
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
- 03-01-2009, 07:43 AM #5
Hi,
I didnt understand the intension of this code. You are comparing data with max and min, which again have the same value as data.
Can you tell us what actually you are trying to do and paste any output/ error you are getting, so that we can help you better.To finish sooner, take your own time....
Nivedithaaaa
- 03-03-2009, 05:52 PM #6
Member
- Join Date
- Feb 2009
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Repeat while answer yes - do while loop
By AJ2009 in forum New To JavaReplies: 1Last Post: 01-10-2009, 06:19 PM -
Why is the answer not coming out
By anonymous18 in forum New To JavaReplies: 4Last Post: 11-12-2008, 03:10 AM -
i want my answer to a whole number or i think an int, please help?
By soc86 in forum New To JavaReplies: 3Last Post: 11-02-2008, 01:29 AM -
Plz answer this question ...
By raghu2114 in forum Advanced JavaReplies: 2Last Post: 09-19-2008, 06:36 PM -
guss which is correct answer
By abhinav_jain09 in forum Java AppletsReplies: 4Last Post: 09-19-2008, 02:39 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks