ACM模式输出模板:
import java.util.Scanner;
public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); } }
输入浮点:float n = sc.nextFloat();
取整:
1.Math.round(n)
2.ans-( int )ans>= 0.5 ?( int )(ans+ 1 ):( int )ans
HJ6质数因子:功能:输入一个正整数,按照从小到大的顺序输出它的所有质因子(重复的也要列举)(如180的质因子为2?2?3?3?5?)
hashMap遍历:
for(Map.Entry num : map.entry.entrySet()){
? ? ? ? System.out.println(num.getKey() + " " +num.getValue());
}
import java.util.Scanner;
import java.util.ArrayList;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 2;i<=n;i++){ //给k值赋值最小质数2
while(n!=i){
if(n%i==0){
System.out.print(i+" ");
n=n/i;
}else{
break; //如果不能整除,那么就让k++(先跳出while在++)
}
}
}
System.out.print(n + " ");
}
}
|