package rangecounter; import java.util.Scanner; public class RangeCounter { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input = new Scanner(System.in); int count1 = 0, count2 = 0, count3 = 0, count4 = 0; for (int i = 1; i <= 20; i++) { System.out.print("Enter number " + i + ": "); int num = input.nextInt(); if (num >= 1 && num <= 50) { count1++; } else if (num >= 51 && num <= 100) { count2++; } else if (num >= 101 && num <= 150) { count3++; } else if (num >= 151 && num <= 200) { count4++; } } System.out.println("Number of values in range 1-50: " + count1); System.out.println("Number of values in range 51-100: " + count2); System.out.println("Number of values in range 101-150: " + count3); System.out.println("Number of values in range 151-200: " + count4); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter