Using Java to organize array input into a table?
I have a program that receives an array. I want to have it organize the results into ranges (like 60-69). It also needs to know how many of the numbers it received fit into which ranges so it can put them in accordingly. The way I've seen to create tabs in a table is
System.out.print("Column1/tColumn2");
How do you go about organizing the array data into a range? Do you specify it with a bunch of IF statements? And I assume you use a counter to tally up how many numbers fit into which ranges?
EDIT: Here's the code at present.
import java.util.Scanner;
import java.lang.Integer;
import java.lang.String;
public class Salary {
int salary;
int sales;
public static void main(String[] args) {
Scanner input = new Scanner ( System.in );
int Salary;
Salary salary = new Salary();
System.out.print( "Please enter the amount each employee brought in:");
String sales = input.nextLine();
String salesArray[] = sales.split(" ");
for(int i=0; i<salesArray.length; i++){
Integer myInt = Integ开发者_开发技巧er.parseInt(salesArray[i]);
System.out.print(salesArray[i] + " ");
if (Integer.parseInt(salesArray[i]) <= 0) {
System.out.println("Please enter a value greater than zero");}
else {
Salary = ((myInt/100) * 9) + 200;
System.out.print(Salary); }
}
int two = 0; //declared a variable, starting it at 0 and intending to increment it
//with input from the array
System.out.print("Range/t#ofEmployees");
for(int i=0; i<salesArray.length; i++) {
if (salesArray[i] <= 200){} //Error on the if statement, using the wrong operand
else{ two++;} //Attempt at the table and increment.
}
}
}
i won't post an implementation, since this is homework, but think of this:
your array can be sorted ...
you can itterate that array, and count something up if the current value is less than a certain boundary ... once it is greater you can print one range and startover for the next range ...
boundaries can change from range to range ...
精彩评论