How can I check if the character equal space?

Wesam Alboishe

I need to check if the array of character [i] equal space or not

Please look at the code:

import java.util.Scanner;

public class Main {
public static void main(String[] args) {

    Scanner in = new Scanner(System.in);
    System.out.println("\tplease enter text");
    System.out.print("\t");
    String text = in.next();

    for(int i =0;i<text.length();i++)
    {
        if(text.charAt(i) == 'a') // case a
        {
            System.out.println("it is  > a");
        }
        else if(text.charAt(i) == ' ') // case space
        {
            System.out.println("it is a  > space");
        }
    }
    
    
}// main

}

Whene (text.charAt(i) == ' ') TRUE It doesn't do the statement

f1sh

text.charAt(i) == ' ' will not be true since you use Scanner's next method and thus your text variable will not contain a space.

By default a Scanner's delimeter is whitespace, so your call of

String text = in.next();

will cause text to only contain data up until the first space of your input. You can verify this using a System.out.println(text).

Use String text = in.nextLine(); instead.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I store 'space' character into a list

How can I check that two array are equal or not?

How can I check if a character is a letter in assembly?

How can i check if a character is in a range of characters?

How i can i traverse a list and check if an equal item contains there?

How can I setup emacs to change space to TAB character for indent?

How can I store a space character in a MySQL CHAR field?

How can I replace the space character in SVN dump branches name?

How can I Add a Character Space after the Date function in PHP

How can I insert space before capitalized character using sed

How to check if a char is equal to an empty space?

How can I check if an element in an array is equal to something in C?

How can i check if two arrays of objects are equal with javascript?

How can I check if two models equal each other in Django?

How can I check if two cells are equal in brainf*ck?

How can I check if two Map objects are equal?

How can I check if two gzipped files are equal?

How can i check all value in the array equal to a certain number

How can I check if all values in a dictionary are equal?

How can I check if a float variable value is equal to 1.08?

how can i make check if an int isnt equal to a number?

How can I check if two GEP instructions are semantically equal or not?

How can I check how much space specific packages occupy?

How can I check how much free space there is in a disk with Python?

Can I check how much space my indexedDB is taking up?

How I can check what takes disk space in /tmp?

How can I check a string without space in MySQL through PHP

How can I check if the user input is a word and not a special character like (*!?)?

How can I check if character in a string is a letter? (Python)

TOP Ranking

HotTag

Archive