Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Prompt the user and receive input for an int variable n. Write a loop that prints 1 through n, separated by commas. E.g., for n = 9 print 1, 2, 3, 4, 5, 6, 7, 8, 9
- */
- import java.util.Scanner;
- public class ForLoop2{
- public static void main(String[] args){
- Scanner kb = new Scanner(System.in);
- System.out.print("Enter a number: ");
- int n = kb.nextInt();
- for(int i = 1; i <= n; i++){
- System.out.print(i);
- if( i != n ) System.out.print(", ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement