How to print a character of string in New Line without using looping statement in Java?|EasyCoding45

How to print a character of string in New Line without using looping statement in Java?


In this tutorial, we are going to learn How to print a character of string in New Line without using looping statement in Java?


Note :-

  • String index Starts from 0.


Program :-(How to print a character of string in New Line without using looping statement in Java?)


import java.util.*;

class printChar

{

Scanner sc=new Scanner(System.in);

String str;

char ch;

int pos;

int len;

public void DisplayChar()

{

System.out.println("Enter String :");

str=sc.next();

System.out.println("Enter The Position of Character you want to print accoding to above String ");

pos=sc.nextInt();

len=str.length();

if(pos>len)

System.out.println("Position is out of index");

else

System.out.println("Character at that position is :"+str.charAt(pos));

}

public static void main(String args[])

{

printChar p=new printChar();

p.DisplayChar();

}

}


Output:-



Comments