Altertaive Array

• December 23rd, 2011, 07:30 PM
HoooBa14
Altertaive Array
Hey guys and i am new and in need of Immediate help !!

Alright here's the question:

Write a complete Java program that asks the user to enter the number of items. Then find
the following **WITHOUT USING ARRAYS:**
1- The value of the maximum item
2- The value of minimum item
3- The number of the items that are greater than 30

What i wrote:
Code java:

```import java.util.*;   public class Q2C { public static void main (String args []) { { int MaxV = 0; int NumV = 0; int MinV = 0; int i; int value = 0;   for (i=0; i <= 10; i++) { System.out.println("Please Enter the value of the items:"); Scanner scan = new Scanner(System.in); value = scan.nextInt(); if (value < 100) MaxV=value+MaxV; else if (value > 50) MinV=value+MinV; else if (value <=30) NumV=NumV++;   }   System.out.println("Your Maximum value is "+MaxV); System.out.println("Your Minimum value is "+MinV); System.out.println("Your items that are valued more than 30 are " +NumV);   }}}```
Output:

Please Enter the value of the items:
1000
Please Enter the value of the items:
100
Please Enter the value of the items:
20
Please Enter the value of the items:
30
Please Enter the value of the items:
40
Please Enter the value of the items:
50
Please Enter the value of the items:
60
Please Enter the value of the items:
760
Please Enter the value of the items:
80
Please Enter the value of the items:
10
Please Enter the value of the items:
30

Your items that are valued more than 30 are 0

But the output is COMPLETELY WRONG !!

• December 23rd, 2011, 09:35 PM
imsuperman05
Re: Altertaive Array
What are the items that need to be inputted?
• December 23rd, 2011, 09:38 PM
HoooBa14
Re: Altertaive Array
Only int items, between 10 and 100 numbers and get the highest number, lowest number and show the quantity of items that are valued over 30
• December 23rd, 2011, 11:23 PM
helloworld922
Re: Altertaive Array
Have you tried stepping through your code line by line? Add a few println statements to see how your program is modifying the variables, or better yet if you know how, use a debugger.

hint: Take a look at your if and if/else statements. It's not computing the min/max correctly. Why? How would you compute the min/max?

Secondly, there's no code to sum up all values greater than 30. What algorithm do you think would be able to accomplish this?

Lastly examine your for-loop conditional. It only lets the user enter in 10 items, but the requirements say the user should input how many items they want to enter. What's needed to accomplish this?
• December 24th, 2011, 05:55 AM
HoooBa14
Re: Altertaive Array
Helloworld922:

Thanks for your reply, I have tried switch statements too but still the same, that's why I join this forum to answers if you don't mind since I'm a total beginner in Java.

Could anyone give me a solution then after the deadline I would love to talk about it :D
• December 24th, 2011, 06:47 AM
Norm
Re: Altertaive Array
To get a design for the program, think about how you would do it manually with a piece of paper.
Make a list of the steps you need to do one thing at a time. Put them in the order that they need to be done.
For example, the first thing you need to do is get the number of numbers the user will give you.
Use that to control a loop.
Inside the loop what do you need to do?