Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an application that accepts up to 20 Strings. Divide them into two lists,

ID: 3678287 • Letter: W

Question

Write an application that accepts up to 20 Strings. Divide them into two lists, one
for short Strings that are five characters or fewer, and the other for long Strings.
After data entry is complete, prompt the user to enter which type of String to
display, and then output the correct list. If there are no Strings in a requested list,
then output an appropriate message. Save the file as DivideStrings.java.

Also you must only use arrays, for loops, while loops, and if else statements and NOT use import java.util.ArrayList;

You can import a scanner but not ArrayList.

Explanation / Answer

DivideStrings.java

package org.students;

import java.util.Scanner;

public class DivideStrings{

   public static void main(String[] args) {
       int i = 0, j = 0, z = 0, size = 0;
       String ssarray[];
       String lsarray[];
       Scanner sc = new Scanner(System.in);Scanner sc1 = new Scanner(System.in);
       while (true) {
           System.out.print("Enter The size of the Array You want to create(Must be less than 20) :");

           size = sc.nextInt();
           if (size >= 0 && size <= 20) {
               ssarray = new String[size];
               lsarray = new String[size];
              
               while (true) {
                   System.out.print("Enter any String:");
                  
                   String str=sc1.nextLine();
                   if (str.length() <= 5) {
                       ssarray[i] = str;
                       i++;
                   } else {
                       lsarray[j] = str;
                       j++;
                   }
                   z++;
                   if (z < size) {
                      
                       continue;
                   }
                   break;
               }// end of while(true) loop
           } else {
               System.out
                       .println("** Please Enter Value Less than or eaual to 20 **");
               continue;
           }
           System.out.println("The Array of small string are ::");
           if(i!=0)
           {
           for (int k = 0; k < i; k++) {
               System.out.println(ssarray[k] + " ");
           }
           }else System.out.println("** The Array Which holds Small strings is empty **");
          
           if(j!=0)
           {
               System.out.println("The Array of Long string are ::");
           for (int l = 0; l < j; l++) {
               System.out.println(lsarray[l] + " ");
           }}else System.out.println("** The Array which holds Long strings is empty **");
           break;
       }// end of while loop.

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote