Results 1 to 2 of 2

Thread: Java question?

  1. #1
    Zeronitic is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default Java question?

    I'm trying to input five numbers in a for loop.
    I want to input five numbers and make it stop.
    I'm not sure how to use System.out.print five times in a for loop and make it stop there.

    Does anyone know?

  2. #2
    SRaith is offline Member
    Join Date
    Oct 2011
    Posts
    14
    Rep Power
    0

    Default Re: Java question?

    Did you mean something like that? o.o

    Java Code:
    import java.util.Scanner;
    
    public class Confusing {
       public static void main(String[] args) {
           Scanner scan = new Scanner(System.in);
           int[] numbers = new int[5];
           
           for(int i = 0; i < numbers.length; i++) {
    	   System.out.print("Please input number " + (i+1) + ": ");
    	   numbers[i] = scan.nextInt();
           }
           
           System.out.println();
           System.out.println("Saved numbers");
           System.out.println("--------------");
           
           for(int i = 0; i < numbers.length; i++) {
    	   System.out.println("Number " + (i+1) + ": " + numbers[i]);
           }
       }
    }

Similar Threads

  1. Java Question
    By Etimer in forum New To Java
    Replies: 7
    Last Post: 02-04-2012, 08:09 AM
  2. Java Question [Beginner Question]
    By joker760 in forum New To Java
    Replies: 3
    Last Post: 12-13-2011, 05:01 PM
  3. Java Question.
    By Taszk in forum New To Java
    Replies: 3
    Last Post: 06-06-2011, 09:15 AM
  4. Replies: 33
    Last Post: 01-21-2011, 04:07 PM
  5. Java question
    By TGH in forum New To Java
    Replies: 12
    Last Post: 11-27-2009, 03:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •