Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to add input in array java

import java.util.Scanner;

class bigest {
    public static void main (String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println ("how many number you want to put in the pot?");
        int num = input.nextInt();
        int numbers[] = new int[num];

        for (int i = 0; i < num; i++) {
            System.out.println ("number" + i + ":");
            numbers[i] = input.nextInt();
        }

        for (int temp : numbers){
            System.out.print (temp + "	");
        }

        input.close();
    }
}
Comment

how to add input in array java

import java.util.Scanner;

    public class Test {

            public static void main(String[] args) {

            int arr[];
            Scanner scan = new Scanner(System.in);
            // If you want to take 5 numbers for user and store it in an int array
            for(int i=0; i<5; i++) {
                System.out.print("Enter number " + (i+1) + ": ");
                arr[i] = scan.nextInt();    // Taking user input
            }

            // For printing those numbers
            for(int i=0; i<5; i++) 
                System.out.println("Number " + (i+1) + ": " + arr[i]);
        }
    }
Comment

PREVIOUS NEXT
Code Example
Java :: how to get key value from json object in java 
Java :: upload converted base64 to image object to oss without saving in java 
Java :: how to overwrite a text file in java 
Java :: android studio breakpoint not working 
Java :: error cannot find symbol intent 
Java :: java.lang.IllegalArgumentException: Invalid character found in method name 
Java :: Validation failed for query for method public abstract java.util.List 
Java :: java download file from url 
Java :: java singleton implementation 
Java :: java scanner string nextline after nextint 
Java :: java zip file 
Java :: on touch listener android 
Java :: java random between two strings 
Java :: android zoom animation 
Java :: java date to string 
Java :: spigot disable join message 
Java :: volley dependency 
Java :: array to list java 
Java :: java leap year 
Java :: java break 2 for loops 
Java :: compare two character alphabetically java 
Java :: create java gui intellij 
Java :: convert javascritp getTime() to datetime 
Java :: android application subclass 
Java :: jframe color 
Java :: spring maven plugin 
Java :: fragment to fragment 
Java :: glide library in android studio 
Java :: current time in long java 
Java :: bukkit java get player count 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =