2020年3月8日 星期日

[zerojudge]a147. Print it all

a147. Print it all

核心:i % 7 == 0? "": i + " "
如果i被7整除就輸出空字串,不整除就輸出i加空白。Yeah

BTW科皓不要

程式碼如下:

  1. /* Pa147.java
  2. * a147. Print it all
  3. *
  4. * 我的意思是說 科皓不要啦
  5. * 2020/3/8
  6. */
  7.  
  8. import java.util.Scanner;
  9.  
  10. public class Pa147{
  11.  
  12. public static void main(String[] args){
  13. Scanner scanner = new Scanner(System.in);
  14.  
  15. while(scanner.hasNext()){
  16. int n = scanner.nextInt();
  17.  
  18. for(int i = 1; i < n; i++){
  19. System.out.print(i % 7 == 0? "": i + " ");
  20. }
  21.  
  22. System.out.println();
  23. }
  24.  
  25. }
  26. }

沒有留言:

張貼留言