How to take input from User as String given the String Length
The problem link:
http://www.practice.geeksforgeeks.org/problem-page.php?pid=295
MyApproach:
I used Scanner for the task to take the number of testcases and then took the String length as input:
But I am confused how to take String of specified length.My search found that there is no method or constructor which can take string of specified length.
Can Anyone guide?
Below is my code:
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=1;i<=T;i++)
{
int Strlength=sc.nextInt();
String strnew=sc.next(); //How to take Stringofspecified character
..........
.........
}
nextLine()) and then just use the first n characters.