sample program using for loop in java.
this program will ask the user to input how many numbers they want to print:
import java.util.Scanner;
public class samplefor
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num;
int x;
System.out.print("How many numbers you want to print:");
num=input.nextInt();
for(x=0; x<=num; x++)
{
System.out.println(x");
}
}
}
No comments:
Post a Comment