I am trying to change the information in create a new character array of Str without the whitespaces. However, I cant succeed in doing sp
I dont know why the output says:
Haveaniceday
Have a nice day
instead of:
Haveaniceday
Haveaniceday
import java.util.*;
class DelExtraSpace
{
public static void main(String args[])
{
char c[],s[];
String str;
Scanner scn = new Scanner(System.in);
str = "Have a nice day";
c = str.toCharArray();
s = new char [c.length];
for(int i = 0; i < c.length; i++)
{
if(!Character.isSpaceChar(c[i]))
{
System.out.print(c[i]);
s[i] = c[i]; // I want the value of c[i] to be assigned to s[i] only when c[i] is not a whitespace
}
}
System.out.println();
for(int j = 0; j < s.length; j++)
System.out.print(s[j]);
}
}