SHARE
TWEET

Untitled

a guest Sep 21st, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. import java.util.Scanner;
  8. public class task10 {
  9.  
  10.     /**
  11.      * @param args the command line arguments
  12.      */
  13.     public static void prA(int a[]){
  14.         for(int i=0; i<a.length; i++)
  15.             System.out.print(a[i]+" ");
  16.     }
  17.        
  18.     public static int[] remove2(int a[], int element){
  19.       int flag=0;
  20.       for(int i=0; i<a.length; i++){
  21.       if(element==a[i]){
  22.         flag++;
  23.       }
  24.       }
  25.       if(flag==0){
  26.         System.out.println("Not found");
  27.         return a;
  28.       }else{
  29.         for(int i=0; i<a.length; i++){
  30.           if(a[i]==element){
  31.             a[i] = 0;
  32.           }
  33.         }
  34.       }
  35.         return a;
  36.       }
  37.      
  38.      
  39.     public static void main(String[] args) {
  40.         Scanner sc = new Scanner(System.in);
  41.         int a[] = {10, 20, 30, 40, 50};
  42.         System.out.println("The source array");
  43.         prA(a);
  44.         System.out.println();
  45.         System.out.println("ENter the element");
  46.         int e = sc.nextInt();
  47.         remove2(a, e);
  48.         prA(a);
  49.         // TODO code application logic here
  50.     }
  51.    
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top