Header Ad

HackerRank Java Loops I problem solution

In this HackerRank Java Loops I problem in the java programming language you have Given an integer, N, print its first 10 multiples. Each multiple N x i (where 1<= i <= 10) should be printed on a new line in the form: N x i = result.

HackerRank Java Loops I problem solution


HackerRank Java Loops I problem solution.

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {



    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])?");

        scanner.close();
        for(int i = 1; i <= 10; i++){

            System.out.printf("%d x %d = %d%n", N, i, N*i);
        }
    }
}



Second solution in java8 programming.

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();
        for(int i = 1; i <= 10; i++){
            System.out.println(input + " x " + i + " = " + input*i);
        }
    }
}

Post a Comment

1 Comments