How to get input 20 characters through loop in Java?|EasyCoding45

 How to get input 20 characters through loop in Java?


In This tutorial, we are going to learn how we can Write a java Program to get 20 input Characters through loop.


Note :- 

1)I have accepted as a String but i have also converted into character and then later Stored in a Character Array.

2)I have taken input only 6 character to show you its working.


Program (How to get input 20 characters through loop in Java?) :-


import java.util.*;

import java.io.*;

class getChar

{

Scanner sc=new Scanner(System.in);

String str;

public void getInput(int n)

{

char ch[]=new char[n];

for(int i=0;i<n;i++)

{

System.out.println("Enter Character "+(i+1)+":" );

str=sc.next();

ch[i]=str.charAt(0);

}

System.out.print("Characters are:");

for(char c:ch)

System.out.print(c);

}

public static void main(String a[])

{

Scanner in=new Scanner(System.in);

System.out.println("Enter How many Characters you want to store :");

int limit=in.nextInt();

getChar g=new getChar();

g.getInput(limit);

}

}


Output :-




Comments