PP 8.2 Modify the program from PP 8.1 so that it works for numbers in the range between −25 and 25
THIS IS MY CODE! please edit this...Thank you
import java.util.Scanner;
public class Array {
public static void main (String[] args) {
Scanner scan = new Scanner (System.in);
int[] integs = new int[51];
System.out.println("Enter integers 0-50 [enter -1 to quit]: ");
int nums = scan.nextInt();
while (nums != -1 && nums>=0 && nums<=50) {
integs[nums]++;
nums = scan.nextInt();
}
for (int index = 0 ; index<=50 ; index++) {
if (integs[index] > 0) {
System.out.println(index+ " : " +integs[index]);
}
}
}
}
import java.util.Scanner; public class Array { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int[] integs = new int[51]; System.out.println("Enter integers -25 - 25 [enter -1 to quit]: "); int nums = scan.nextInt(); while (nums != -1 && nums >= -25 && nums <= 25) { integs[nums+25]++; nums = scan.nextInt(); } for (int index = 0; index <= 50; index++) { if (integs[index] > 0) { System.out.println(index-25 + " : " + integs[index]); } } } }
Get Answers For Free
Most questions answered within 1 hours.