Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Crown {
- public static void main(String[] args) {
- //------------Ex1-----------------------------
- /*
- Scanner sc = new Scanner(System.in);
- int num, powerNum;
- System.out.println("Please enter a number: ");
- num = sc.nextInt();
- for(int i = 1; i <= num; i++) {
- System.out.println("The power of " + i + " is " + i*i + ".");
- }
- */
- //------------Ex2-----------------------------
- /*
- Scanner sc = new Scanner(System.in);
- int num, numOfOdds = 0;
- String s = "";
- System.out.print("Please enter 10 numbers: ");
- for(int i = 0; i < 10; i++) {
- num = sc.nextInt();
- if(num%2 == 1) {
- numOfOdds += 1;
- s += (num + " ");
- }
- }
- System.out.printf("The number of odd numbers is %d", numOfOdds);
- */
- //------------Ex3-----------------------------
- /*
- Scanner sc = new Scanner(System.in);
- int num;
- System.out.print("Please enter a number: ");
- num = sc.nextInt();
- for(int i = 3; i <= num; i += 3) {
- System.out.println(i);
- }
- */
- //------------Ex4-----------------------------
- /*
- Scanner sc = new Scanner(System.in);
- int num;
- System.out.print("Please enter a number: ");
- num = sc.nextInt();
- for(int i = num; i > 0; i--) {
- if(i%3 == 0) {
- System.out.println(i);
- }
- }
- */
- //------------Ex5-----------------------------
- /*
- Scanner sc = new Scanner(System.in);
- int num;
- System.out.print("Please enter a number: ");
- num = sc.nextInt();
- for(int i = 1; i <= num; i += 1) {
- if(i % 7 == 0) {
- System.out.println("Boom!");
- } else {
- System.out.println(i);
- }
- }
- */
- //------------Ex6-----------------------------
- Scanner sc = new Scanner(System.in);
- int num, temp = 0;
- System.out.print("Please enter a number: ");
- num = sc.nextInt();
- for(int i = 3; i <= num; i += 3) {
- for(int j = i; j > 0; j/=10) {
- temp += j%10;
- }
- if(temp < 5) {
- System.out.println(i);
- }
- temp = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement