We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Introduction
- Java Loops I
- Discussions
Java Loops I
Java Loops I
Sort by
recency
|
1431 Discussions
|
Please Login in order to post a comment
/*This is the simple and easy method to solve this question, i just simply run loop with the 2 number given in problem set and do arithematic calculation and then print as per the guideline, I use for loop cause i know how many time loop is going to run then this section is more easy to understand which i given below: Syntax of for loops:
System.out.println(n + " x " + i + " = " + (n * i)); n + " x " When you use + with a number and a string, Java converts the number to text and concatenates. If n is 5, this produces "5 x ". + i + " = " Next, Java takes that result and appends the current loop index i, then the literal " = ". If i is 3, you now have "5 x 3 = ". + (n * i) The expression inside parentheses (n * i) is evaluated first (so you multiply two integers). If n = 5 and i = 3, that gives 15, which is then converted to the string "15" and appended. System.out.println(...) Finally, println prints that full string and moves to a new line. Putting it all together, when n = 5 and i = 3, you get: Copy code 5 x 3 = 15 .................................................................If you like my solution,approach hit the one like for appreciation. */
import java.util.Scanner;
public class hackerrankloop { public static void main(String[] args) { Scanner sc = new Scanner(System.in);
}
java 15
for (int i=1; i <=10; i++){ System.out.println(N+" x "+i+" = "+N*i); }
Here is Java Loops 1 problem solution - https://programmingoneonone.com/hackerrank-java-loops-i-problem-solution.html