2013年12月10日星期二

How can the space can be considered out that way?

package Test;

import java.util *.;
public class Ex_12
{
public static void main (String [] args)
{/ / lowercase
int letter = 0;
/ / uppercase
int Letter = 0;
/ / Digital
int digit = 0;
/ / special characters
int other = 0;
/ **
* " standard " input stream. This stream is already open and ready to provide input data.
Typically this stream corresponds to keyboard input or another input source specified by the host environment or user.
inputSteam source parameter is a variable ,
class system of constant public static final InputStream in - "System.in
*
* /
/ / Constructs a new Scanner, the value of which is generated from the specified input stream scan.
Scanner Input = new Scanner (System.in);
System.out.println (" Please enter the string" ) ;
String ch = Input.next ();
/ / array length is a property , String of length is a method ,
/ / i ch is not less than or equal length , only less than
for (int i = 0; i {
if (ch.charAt (i)> = 'a' && ch.charAt (i) <= 'z')
letter + +;
else if (ch.charAt (i)> = 'A' && ch.charAt (i) <= 'Z')
Letter + +;
else if (ch.charAt (i)> = '0 '&& ch.charAt (i) <= '9')
digit + +;
else
other + +;
}
System.out.println ("letter =:" + letter);
System.out.println ("Letter =:" + Letter);
System.out.println ("digit =:" + digit);
System.out.println ("other =:" + other);
}

}
------ Solution ----------------------------------- ---------
if (word.charAt(i) == ' ')
'' inside a space
------ For reference only ----------- ----------------------------


int digit = 0;
/ / special characters
int other = 0;
int Null = 0;

.....
else if (ch.charAt (i)> = '0 '&& ch.charAt (i) <= '9')
digit + +;
else if (ch.charAt (i) == '')
Null + +;
else
other + +;

.....
System.out.println ("Kongge =:" + Null);
still ah
------ For reference only ------------------------------- --------
is not in the spaces removed. There is no way to calculate with Scanner spaces come from?
------ For reference only -------------------------------------- -
you try to put a space in the string , you're the last line of the box into the right ?
------ For reference only -------------------------------------- -

public static void main(String[] args)
    {
        // 小写
        int letter=0;
        // 大写
        int Letter=0;
        // 数字
        int digit=0;
        // 特殊字符
        int other=0;
        // 空格
        int blank=0;
        
        Scanner Input = new Scanner(System.in);
        System.out.println("请输入字符串");
        String ch= Input.nextLine();
        // 数组length是属性,String的length是方法,
        // i不能小于等于ch的长度,只能小于
        for(int i=0;i<ch.length();i++) {
            if(ch.charAt(i)>='a' && ch.charAt(i)<='z')
                letter++;
            else if(ch.charAt(i)>='A' && ch.charAt(i)<='Z')
                Letter++;
            else if(ch.charAt(i)>='0' && ch.charAt(i)<='9')
                digit++;
            else if (ch.charAt(i) == ' ')
                blank++ ;
            else 
                other++;
        }
        System.out.println("letter=:"+letter);
        System.out.println("Letter=:"+Letter);
        System.out.println("digit=:"+digit);
        System.out.println("blank=:"+blank);
        System.out.println("other=:"+other);
    }



请输入字符串
fdj fdjaskjfdsa fdjaskFDSAre32
letter=:22
Letter=:4
digit=:2
blank=:2
other=:0

------ For reference only --------------------------------- ------
String ch = Input.nextLine (); I'm wrong here , String ch = Input.next (); Thank

没有评论:

发表评论