How to Read String Array in Java

Take String Array input in Coffee language

Take String Assortment input in Java language

Contents

  • 1 Accept String Array input in Coffee linguistic communication
    • 1.1 Lawmaking to  fill string array elements of assortment
      • ane.1.i Program to fill Cord in assortment using for loop
      • 1.1.2 Programme to make full String assortment using while loop
      • one.1.three Program to fill Cord in an assortment using do-while loop
    • 1.ii Related posts:

In this tutorial, we will discuss the concept ofTake Cord Assortment input in Java language

In this topic, nosotros are going to learn how to take string assortment input in Java programming linguistic communicationusing for, while and do-while loops.

In this blog, We have already talk over that "What is an assortment", type of arrays and how to admission it(one dim, two dim and three dim arrays)

Arrays are the special type of variables to store Multiple type of values(int, string,char, etc)under the same name in the continuous memory location. we can be easily accessed using the indices(indexes)

string elemnts - Take String Array input in Java language
Print String assortment elements

Here,

  • s1,s2,s3,s4 and s5 represent the string elements of the assortment
  • 0,1,2,3 and four represent the index of the assortment which is used to admission the array elements
  • 1,ii,3,four and 5 stand for the length of the array

Code to  make full string assortment elements of assortment

Program to fill Cord in array using for loop

In this plan, we are briefing how to take input  String elements  of an array using for loop in Coffee linguistic communication

Plan one

import coffee.util.Scanner; public class TakeStringArrayInputfor{ public static void main(String args[]){ //scanner course to read input from the user     Scanner sc=new Scanner(System.in);     //Declaring and creating String array     String[] arr=new Cord[4];          //Brandish default value after declaring     System.out.println("Default values of given String assortment: ");     for(int i=0; i<arr.length; i++){         Organization.out.println(arr[i]+"\t");     }//find default value of the given array     System.out.println("");     //initializing value to the array     Organisation.out.println("******Initializing array******");     System.out.println("Enter "+arr.length+" string values");     for(int i=0; i<arr.length; i++){         arr[i]=sc.nextLine();     }//using the for loop to initializing assortment          //displaying the array elements     System.out.println("\n******displaying assortment elements******");     Organisation.out.println("Entered Strings are");     for(int i=0; i<arr.length; i++){         Organization.out.println(arr[i]+"\t");     } } }        

When the higher up code is executed, information technology produces the following result

Default values of given String assortment: null null zippo aught  ******Initializing array****** Enter 4 String value Ani Abi Kavi Puvi  ******displaying array elements****** Entered Strings are Ani Abi Kavi Puvi

Programme to make full String array using while loop

In this program, we are briefing how to input  Cord elements  of an array using while loop in Java language

Programme 2

import coffee.util.Scanner; public grade TakeStringArrayInputWhile{ public static void primary(String args[]){ //scanner class to read input from the user     Scanner sc=new Scanner(System.in);     //Declaring and creating String array     String[] arr=new Cord[four];          //Display default value later on declaring     System.out.println("Default values of given String assortment: ");     int i=0;      while(i<arr.length){         Organisation.out.println(arr[i]+"\t");         i++;     }//observe default value of the given array           System.out.println("");     //initializing value to the array     Arrangement.out.println("******Initializing array******");     System.out.println("Enter "+arr.length+" String values");     i=0;     while(i<arr.length){         arr[i]=sc.nextLine();          i++;     }//using the for loop to initializing array          //displaying the array elements     System.out.println("\north******displaying assortment elements******");     System.out.println("Entered array elements are");     i=0;     while(i<arr.length){         Arrangement.out.println(arr[i]+"\t");          i++;     } } }        

When the in a higher place lawmaking is executed, it produces the following result

Default values of given String assortment: nil aught naught cypher  ******Initializing array****** Enter 4 String value Krish Muru Saman Sonu  ******displaying assortment elements****** Entered Strings are Krish Muru Saman Sonu

Program to fill Cord in an array using exercise-while loop

In this program, we are briefing how to input  Cord elements  of an assortment using do-while loop in Java language

Programme 3

import java.util.Scanner; public form TakeStringArrayInputDoWhile{ public static void chief(String args[]){ //scanner class to read input from the user     Scanner sc=new Scanner(Organization.in);     //Declaring and creating String array     String[] arr=new String[5];          //Display default value after declaring     System.out.println("Default values of given Cord array: ");     int i=0;      practice{         System.out.println(arr[i]+"\t");         i++;     }while(i<arr.length);     //find default value of the given array           Organization.out.println("");     //initializing value to the assortment     System.out.println("******Initializing assortment******");     System.out.println("Enter "+arr.length+" String values");     i=0;     practice{         arr[i]=sc.nextLine();          i++;     }while(i<arr.length);     //using the do-while loop to initializing assortment          //displaying the array elements     Organisation.out.println("\n******displaying array elements******");     System.out.println("Entered Strings are are");     i=0;     do{         Arrangement.out.println(arr[i]+"\t");          i++;     }while(i<arr.length); } }        

When the above code is executed, information technology produces the following result

Default values of given String assortment: null cypher nix cypher null  ******Initializing assortment****** Enter 5 String value Sivaji Pirapu Kamal Rajani Ajith  ******displaying array elements****** Entered Strings are Sivaji Pirapu Kamal Rajani Ajith

Similar mail

Code to read and print integers of an array in Java

Code to read and print strings of an assortment in Java

Code to read and print characters of an array in Java

Code to read and impress integers of an array in C++

Lawmaking to read and print strings of an array in C++

Code to read and print characters of an assortment in C++

Code to read and print integers of an array in C

Code to read and print strings of an array in C

Suggested f or you lot

Array in Programming linguistic communication

Ane dimensional array in C language

Ane dimensional array in C++ language

2 dimension array in Java language

Two dimension array in C linguistic communication

Ii dimension array in C++ language

Three dimension assortment in Coffee language

Iii dimension array in C language

Iii dimension assortment in C++ language

for loop in Java language

while loop in Coffee language

Practise-while loop in Coffee language

Enhanced for loop in Java language

Data  blazon and variable in Coffee linguistic communication

Operator in Java language

paulefors1941.blogspot.com

Source: https://code4coding.com/take-string-array-input-in-java-language/

0 Response to "How to Read String Array in Java"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel