dm6801

20171109 - 03 - classEx_04

Nov 11th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. package myApp;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class class03_ex04 {
  6.  
  7.     public static void main(String[] args) {
  8.         //init vars
  9.         int n       = 0;
  10.        
  11.         //usage msg
  12.         System.out.println("Integer: ");
  13.        
  14.         //open in_Stream, parse & close
  15.         Scanner s = new Scanner(System.in);
  16.         n = s.nextInt();
  17.         s.close();
  18.        
  19.         /* Method 1 */
  20.         //loop Until i regresses to 0, and include 0
  21.         for (int i=n; i>=0; i-=1) {
  22.             if (i%3 == 0) { System.out.println(i); } //check if i/3 = Integer, and print n if yes
  23.         }
  24.        
  25.         /* Method 2
  26.         //overwriting n, therefore destroying data that was input by user - bad practice??
  27.         for (int i=0; i<=n; n-=1) {
  28.             if (n%3 == 0) { System.out.println(n); } //check if i/3 = Integer, and print n if yes
  29.         }*/
  30.        
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment