Facebook
From ddddd, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 126
  1. import java.util.Scanner;
  2. public class Ex1 {
  3.  
  4.  public static void main(String[] args) {
  5.   Scanner input = new Scanner(System.in);
  6.   System.out.println("Enter the number of students: ");
  7.   int nbS = input.nextInt();
  8.   int age;
  9.   String name;
  10.   int counter = 0;
  11.  
  12.   for(int i=1; i<=nbS; i++)
  13.   {
  14.    System.out.println("Enter the student's name: ");
  15.    name = input.next();
  16.    System.out.println("Enter the student's age: ");
  17.    age = input.nextInt();
  18.    if(age<20)
  19.     counter++;
  20.   }
  21.   System.out.println("Total number of students under age 20: "+counter);
  22.  
  23.  
  24.  }
  25.  
  26. }
  27.