Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Altertaive Array

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down 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:
    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 Maximum value is 320
    Your Minimum value is 1860
    Your items that are valued more than 30 are 0


    But the output is COMPLETELY WRONG !!

    Deadline is like Hours from now ----- HELP ME PLEASE !!!!!
    Last edited by helloworld922; December 24th, 2011 at 12:17 AM.


  2. #2
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Altertaive Array

    What are the items that need to be inputted?

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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?

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default 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?

Similar Threads

  1. Replies: 4
    Last Post: November 14th, 2011, 10:00 PM
  2. Doubling The Array Size And Randomizing Array Return
    By Pingu00 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: June 27th, 2011, 10:50 AM
  3. Replies: 2
    Last Post: May 13th, 2011, 03:08 AM
  4. Replies: 2
    Last Post: May 6th, 2011, 05:19 PM
  5. 2d (4x4) array insdie a 1d array. (Block cipher)
    By fortune2k in forum Collections and Generics
    Replies: 13
    Last Post: November 23rd, 2010, 05:29 PM