Results 1 to 3 of 3
Thread: A newb question
- 03-29-2012, 11:41 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
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("--------------------------------------");
}
}
- 03-30-2012, 12:00 AM #2
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.
- 03-30-2012, 07:00 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
newb needs help
By dumle29 in forum New To JavaReplies: 3Last Post: 02-24-2011, 08:43 AM -
Newb here, need help with JSP.
By grep in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-25-2010, 09:04 PM -
Hello, I'm a newb
By smith427 in forum New To JavaReplies: 1Last Post: 12-03-2009, 02:54 AM -
[SOLVED] Probably a tooootal newb question... but
By proeliumfessus in forum New To JavaReplies: 6Last Post: 04-05-2009, 07:07 PM -
Newb Topics
By dkizzy in forum New To JavaReplies: 2Last Post: 09-17-2008, 07:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks