#include<iostream>
unsigned print_naturals (unsigned max)
{
unsigned num = 0;
while (num<max)
std::cout << ++num << ' ';
std::cout << std::endl;
}
int main()
{
// print first 10 natural numbers:
print_naturals (10);
// print first 100 natural numbers:
print_naturals (100);
}
Chat with our AI personalities
Here's a program that ask for a number and then prints the list of numbers and their running sum:
main
SUB main
INPUT "What is the final number"; final
j = 0
PRINT " Number", " Running Count"
FOR i = 1 TO final
j = i + j
PRINT STR$(i), j
NEXT i
END SUB
public class Test {
public static void main(String args[]){
for(int i = 0; i < 1000; i++){
System.out.println(i);
}
}
}
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
To print lucky numbers in java, you must give the following program: class example { static public void main(String[] args) { System.out.println("Lucky number is your favourite number which is your DOB"); } }
The Java console is a display of output sent by a Java program. This is similar to the MS DOS operating system.To print to the console, a programmer will type "println(text);" or "print(text);" depending is the programmer wants to make a new line after the text(println) or not(print).
If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).
JAVA