to input a number from the user and print it in java
Answers
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]);
}
}
}
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]);
}
}
}