Java Loop1

Kali ini kita akan menggunakan loops untuk membuat simple problem math.

Task

Ada bilangan integer N , print 10 kali, dimana setiap perulangan N x i (where 1<=10 i <=10) harus dicetak N x i =result.

Input Format

Single Integer N

Constraints

2 <= N <=20

Sample Input

2

Code

import java.util.Scanner;

public class Loops1 {
    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
        int result=0;
        for(int i=1;i<=10;i++){
            result=N*i;
            System.out.println(N+" x "+i+" = "+result);
        }

        scanner.close();
    }
}

Output

2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20

hyvercode