华为在线OJ_找7

时间:2023-03-09 16:51:28
华为在线OJ_找7
描述

输出7有关数字的个数,包括7的倍数,还有包含7的数字(如17,27,37...70,71,72,73...)的个数

知识点 循环
运行时间限制 0M
内存限制 0
输入

一个正整数N。(N不大于30000)

输出

不大于N的与7有关的数字个数,例如输入20,与7有关的数字包括7,14,17.

样例输入 20
样例输出 3
/*
* ok
*(1) 将scStr.nextInt()理解,对应的左边也要是int型
*(2)之前字符串的时候是str.nextLine().左边对应的是String型
*(3)注意Java中定义整形或者字符型或者字符串型都是用new的
* 格式是 int sum[]=new int[开辟大小];//开辟一个整形数组
* char ch[]=new char[开辟大小];//开辟一个字符型数组
* (4) 对于位置长度的可以用向量Vector来存储
* Vector<String> store=new Vector<String>();
* Vector<Integer> store=new Vector<Integer>();而且整形不是用int,而是Integer
*
*/
package t0806; import java.util.Scanner;
import java.util.Vector; public class huawei5 {
static int count;
public static void main(String[] args) { System.out.println("请输入数字:");
Scanner scStr = new Scanner(System.in); //从键盘获取字符串
count= scStr.nextInt(); //将Scanner对象中的内容以字符串的形式取出来
int count1=count;int count2=0;
Vector<Integer> store=new Vector<Integer>();
for(int i=1;i<count1;i++){
if(i%7==0){
store.addElement(i); count2++;
}
else{
//将i拆分成字符串形式
int sqy=0;int mxf=0;
mxf=i;
while(true){
sqy=mxf-(mxf/10)*10;
if(sqy==7){
store.addElement(i);count2++;
break;
} //一位一位开始break,一旦各位开始就break
mxf=(mxf/10);
if(mxf==0){ //如果为0跳出循环
break;
}
}
}//else
}
System.out.println(count2); }
}