हिंदी

Write a program for the following. Create an array AW[ ] of type int and size 8 and fill it with variables. Print those elements which have last digit 3. For example: Input 33 87 35 8 183 21 76 403

Advertisements
Advertisements

प्रश्न

Write a program for the following.

Create an array AW[ ] of type int and size 8 and fill it with variables. Print those elements which have last digit 3.

For example:

Input 33 87 35 8 183 21 76 403 539
Output 33 183 403
कोड लेखन
Advertisements

उत्तर

import java.util.Scanner;
public class FilterElements 
{
    public static void main(String[] args) 
    {
        int AW[] = new int[8];
        Scanner sc = new Scanner(System.in);
        
        System.out.println("Enter 8 integer elements:");
        for (int j = 0; j < AW.length; j++) 
        {
            AW[j] = sc.nextInt();
        }
        
        System.out.println("\nElements ending with the digit 3:");
        for (int j = 0; j < AW.length; j++) 
        {
            if (AW[j] % 10 == 3) 
            {
                System.out.print(AW[j] + " ");
            }
        }
        sc.close();
    }
}
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 7: Arrays - One Dimension - Exercises [पृष्ठ १७६]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 7 Arrays - One Dimension
Exercises | Q 4. (i) | पृष्ठ १७६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×