Computer Science, asked by Sayani07, 1 year ago

to input a number from the user and print it in java

Answers

Answered by jadepilot6484
1

Answer:

Explanation:

Hey There!!

Here's your code:

import java.util.Scanner;

public class Array

{

   public static void main(String[] args)

   {

       Scanner sc = new Scanner(System.in);

       

       System.out.print("Enter the number of elements of array: ");

       int len = sc.nextInt();

       

       System.out.println();

       

       String str[] = new String[len];

       

       for(int i=0;i<len;i++)

       {

           System.out.print("Enter Element Number "+(i+1)+": ");

           str[i] = sc.next();

       }

       

       System.out.println();

       

       System.out.println("The Array is: \n");

       

       for(int i=0;i<len;i++)

       {

           System.out.println(str[i]);

       }

 

   }

}

Answered by acsahjosemon40
1

Answer:

Here's your code:

import java.util.Scanner;

public class Array

{

   public static void main(String[] args)

   {

       Scanner sc = new Scanner(System.in);

       

       System.out.print("Enter the number of elements of array: ");

       int len = sc.nextInt();

       

       System.out.println();

       

       String str[] = new String[len];

       

       for(int i=0;i<len;i++)

       {

           System.out.print("Enter Element Number "+(i+1)+": ");

           str[i] = sc.next();

       }

       

       System.out.println();

       

       System.out.println("The Array is: \n");

       

       for(int i=0;i<len;i++)

       {

           System.out.println(str[i]);

       }

 

   }

}

Similar questions