PRINT SUM OF NATURAL NUMBER IN JAVA

In this code, the user is prompted to enter a positive integer. Then, a for loop is used to iterate from 1 to the given number (n). The loop adds each number to the sum variable. Finally, the result is printed to the console. Note that the code assumes the user will enter a positive… Continue reading PRINT SUM OF NATURAL NUMBER IN JAVA

Print Table in Java

In Java, loops are used to execute a block of code repeatedly based on a certain condition. There are several types of loops available in Java: for loop: The for loop is commonly used when you know the number of iterations in advance. It has three parts: initialization, condition, and increment and decrement. The loop… Continue reading Print Table in Java