Udemy coupon 100 off 2017 ::Udemy coupon code free :: Get 100+ Free Udemy coupons Here

Split the numbers list based on odd & even and list of Strings based Starting character

Split the numbers list based on odd & even

Here is output :





Source code: 

import java.io.*;
class SplitListForNumbers
{
   public static void main(String args[]) throws IOException
{

int i;
int [] array_values=new int[50];
  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter the Total Number Of  Elements You Want to Enter : ");
  int n=Integer.parseInt(br.readLine());

   System.out.println("Now enter the values  : ");
  for(i=0;i<n;i++)
{
         array_values[i]=Integer.parseInt(br.readLine());
     }

    System.out.println("Even List is:  ");
   for(i=0;i<n;i++)
{
        if(array_values[i]%2==0)
{
                  System.out.println(array_values[i]);
             }
}

System.out.println("Odd List is :  ");
                 for(i=0;i<n;i++)
{
            if(array_values[i]%2!=0)
{
         System.out.println(array_values[i]);
}
}
}
}

  • Save the file with name SplitListForNumbers.java 
  • Complie with: javac SplitListForNumbers.java
  • Run with: java SplitListForNumbers


Split the list of Strings based Starting character.

Out Put is as following :


Source code: 

import java.io.*;
class SplitListForString
{
   public static void main(String args[]) throws IOException
{
int i;
boolean t=false;
char comp[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
String [] array_values=new String[50];
  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter the Total Number Of  Elements You Want to Enter : ");
  int n=Integer.parseInt(br.readLine());

   System.out.println("Now enter the values  : ");
  for(i=0;i<n;i++)
{
         array_values[i]=br.readLine();
     }

for(i=0;i<26;i++)
{
t=false;
System.out.println(" \n \n----------------------------"+"List with char  " + comp[i] + "-------------------------");
for(int j=0;j<n;j++)
{
if(comp[i]==array_values[j].charAt(0))
{
System.out.println(    array_values[j]);
t=true;
}
}
if(!t)
{
System.out.println(    "No Entries Found !");
}
     }
}
}

  • Save the file with name SplitListForString.java 
  • Complie with: javac SplitListForString.java
  • Run with: java SplitListForString