Advertisement
MrDoyle

For) Counting with a For Loop

Nov 13th, 2020
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main( String[] args )
  5.     {
  6.         Scanner keyboard = new Scanner(System.in);
  7.  
  8.         System.out.println( "Type in a message, and I'll display it five times." );
  9.         System.out.print( "Message: " );
  10.         String message = keyboard.nextLine();
  11.  
  12.         for ( int n = 2 ; n <= 10 ; n = n+2 )
  13.         {
  14.             System.out.println( n + ". " + message );
  15.         }
  16.  
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement