Results 1 to 3 of 3

Thread: A newb question

  1. #1
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default A newb question

    Heres my code, i got it to so what i want with this array except the problem is i need to limit the user input between 0 and 50. Any help would be appreciated! This is my first post so forgive me if i put htis in the wrong section:::

    import java.util.*;
    public class Lab5 {
    public static void main(String [] args){
    Scanner input = new Scanner(System.in);
    int[] array;
    array = new int[12];

    do{
    System.out.println("Please enter the monthly income for January: ");
    array[0] = input.nextInt();
    System.out.println("Please enter the monthly income for February: ");
    array[1] = input.nextInt();
    System.out.println("Please enter the monthly income for March: ");
    array[2] = input.nextInt();
    System.out.println("Please enter the monthly income for April: ");
    array[3] = input.nextInt();
    System.out.println("Please enter the monthly income for May: ");
    array[4] = input.nextInt();
    System.out.println("Please enter the monthly income for June: ");
    array[5] = input.nextInt();
    System.out.println("Please enter the monthly income for July: ");
    array[6] = input.nextInt();
    System.out.println("Please enter the monthly income for August: ");
    array[7] = input.nextInt();
    System.out.println("Please enter the monthly income for September: ");
    array[8] = input.nextInt();
    System.out.println("Please enter the monthly income for October: ");
    array[9] = input.nextInt();
    System.out.println("Please enter the monthly income for November: ");
    array[10] = input.nextInt();
    System.out.println("Please enter the monthly income for December: ");
    array[11] = input.nextInt();

    System.out.println(array[0]);


    }while(input.nextInt()<= 50 & >=0);


    }


    public static void divider(){
    System.out.println("--------------------------------------");
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default Re: A newb question

    To validate that the input is in range use an if statement that tests the input value against the end of the range values.

    Do you know how to use arrays? Your code would be much simpler if you put the name of the months in an array and used a loop's index variable to get the name of the month from the array and to store the value that the user entered.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: A newb question

    No im very new to arrays. This is the first time ive tried to use them :/ Thanks for the help :)

Similar Threads

  1. newb needs help
    By dumle29 in forum New To Java
    Replies: 3
    Last Post: 02-24-2011, 08:43 AM
  2. Newb here, need help with JSP.
    By grep in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-25-2010, 09:04 PM
  3. Hello, I'm a newb
    By smith427 in forum New To Java
    Replies: 1
    Last Post: 12-03-2009, 02:54 AM
  4. [SOLVED] Probably a tooootal newb question... but
    By proeliumfessus in forum New To Java
    Replies: 6
    Last Post: 04-05-2009, 07:07 PM
  5. Newb Topics
    By dkizzy in forum New To Java
    Replies: 2
    Last Post: 09-17-2008, 07:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •