1066输入空格就自动结束了,怎么才能继续呢?
如输入1234 a...,用sr.length()出来的结果就是4
猴,因为我用的是next(),应该用nextLine()
import java.util.Scanner; public class demo1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String c =input.nextLine(); int shuzi = 0; int zimu = 0; int qita = 0; // System.out.println(c.length()); for (int i = 0; i < c.length(); i++) { char k = c.charAt(i); if(k>='0'&&k<='9') shuzi+=1; else if(k>='a'&&k<='z'||k>='A'&&k<='Z') zimu+=1; else if(k==00) qita+=1; else qita+=1; } System.out.println("letter:"+zimu); System.out.println("digit:"+shuzi); System.out.println("other"+qita); } }
但是错啦,因为是以回车符结束的嘛,也要加一个条件,是否=='\n',这原来也是可以算单个字符呀
(3条消息) ZZULIOJ 1068: 二进制数 (Java)_张大江_bingo的博客-CSDN博客
import java.util.Scanner; public class demo1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int m = input.nextInt(); int k = input.nextInt(); int a = m/k; int day = a+m; while (a==0){ day += (a/k); } System.out.println(day); } }