0% found this document useful (0 votes)
61 views2 pages

Import Public Class Public Static Void Int New: "Introduceti Numarul de Elemente: "

This Java program defines a Vector class with a main method that takes user input to define the size of an integer array and populate it with elements. It then prints out the populated array. The program uses Scanner and BufferedReader to take integer input from the user, stores it in an array of the input size, and finally prints out the array.

Uploaded by

Dragu Stelian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views2 pages

Import Public Class Public Static Void Int New: "Introduceti Numarul de Elemente: "

This Java program defines a Vector class with a main method that takes user input to define the size of an integer array and populate it with elements. It then prints out the populated array. The program uses Scanner and BufferedReader to take integer input from the user, stores it in an array of the input size, and finally prints out the array.

Uploaded by

Dragu Stelian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;
public class Vector
{
public static void main(String[] args)
{
int number;
Scanner in = new Scanner(System.in);
System.out.println("Introduceti numarul de elemente: ");
number = in.nextInt();
int tab[] = new int[number];
System.out.println("Introduceti elementele vectorului: ");
for (int i=0; i<number; i++)
{
System.out.print("tab[" + i + "] = ");
tab[i] = in.nextInt();
}
System.out.println();;
for (int i=0; i<number; i++)
{
System.out.print(" " + tab[i]);
}
}
}

import java.io.*;
public class Vector
{
public static void main(String args[])throws Exception
{
int number;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Introduceti numarul de elemente: ");
number = Integer.parseInt(br.readLine());
int tab[] = new int[number];
System.out.println("Introduceti elementele vectorului: ");
for (int i=0; i<number; i++)
{
System.out.print("tab[" + i + "] = ");
tab[i] = Integer.parseInt(br.readLine());
}
System.out.println();;
for (int i=0; i<number; i++)
{
System.out.print(" " + tab[i]);
}
}
}

You might also like