Arrays in Java (Exercise 1)

preview_player
Показать описание
Java Programming: Programming Question on Arrays in Java Programming
Topics Discussed:
1) Writing a program that fills an array with n integers entered by the user.
2) Writing a program that fills an array with n Points entered by the user.

Music:
Axol x Alex Skrindo - You [NCS Release]

#JavaByNeso #JavaProgramming #ArraysInJava
Рекомендации по теме
Комментарии
Автор

public class array {

public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println(" please enter the number ");
int n=in.nextInt();
while (n>20 || n<1)
{
number please try again ");
n=in.nextInt();
}
int []arr=new int[n];
fillarr(arr);
printarr(arr);
}
public static void fillarr(int []arr)
{
Scanner s=new Scanner(System.in);
for (int i=0;i<arr.length;i++)
{
arr[i]=s.nextInt();
}
}

public static void printarr(int []arr)
{

}
}

thivagarmurugan
Автор

You are very good at Java. Wish you good luck for your future

mcbotface
Автор

The first example is great for a beginner to understand.
The second example is too complicated.

wesjales
Автор

It is showing an error as (point cannot be resolved as a type)...if we try with point[] in eclipse..can u pls help with it

t.lakshmiprasanna
Автор

Sir ur explanation is very useful..
When u will upload pythan clases sir

manognamanu
Автор

how to create the method class in VS code as shown above by using alt and enter?

racecarguy
Автор

Instead of OR operator can we use AND operator. If so, what happens?

dharavathrajkumar
Автор

Scanner s = new Scanner(System.in);


System.out.println("Enter how large you want this array from 1 - 20");
int a = s.nextInt();

while (a < 1 || a > 20) {
System.out.println("Please enter an integer between 1-20");
a = s.nextInt();
}
int[] array = new int[a];

System.out.println("Enter what integer you want to fill in this array");

Arrays.fill(array, s.nextInt());


acunit
Автор

Im using eclipse for java programming. In eclipse the (toString) not working. Can you help me with this ?

sahayaarulanandageethans
Автор

why should we print the array using 'Arrays' class? How do I print without using the arrays class?

kalyansandeep
Автор

how abot if they put 25 ? it it goest forever . i think u need to use(break:} after while condition

ferhatf
Автор

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

System.out.println("Write how many numbers you wanna fill the array with:");
int n = sc.nextInt();

if (n <= 20 && n > 0) {
int[] arr = new int[n];
fill(arr);

System.out.println("These are the contents");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]);
}
}
}

static int[] fill (int[] arr) {
Scanner sc = new Scanner(System.in);

for(int i = 0; i < arr.length; i++) {
System.out.println("Write a number:");
int n = sc.nextInt();
arr[i] = n;
}
return arr;
}

kevinbanan
Автор

Sir, I have one doubt. I cannot able to use Point in Online GDB compiler sir. Can you explain me how to resolve that error. It shows that "cannot able to find the symbol point" while compiling the program. What is the Error?

manikandana
Автор

Is it possible to solve this without using methods??

cherryblossom
Автор

sir please make videos on vlsi design, electronics

vittalkulkarni
Автор

import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

//enter number from 1 to 20// fill the array.
Scanner input = new Scanner(System.in);

System.out.print("how many value do you want to add : ");
int add = input.nextInt();

if (add >= 1 && add <= 20) {
int[] numbers = new int[add];
for (int i = 0; i < add; i++) {

System.out.print((i + 1) + ". number : ");
int number = input.nextInt();

numbers[i] = number;
}



System.out.println("The Elements : "+Arrays.toString(numbers));
} else {

System.out.println("please enter a number from 1 to 20");

}
input.close();
}
}

softwaredeveloper
Автор

Scanner milan = new Scanner(System.in);
System.out.println("Select the size of the array");
int n = milan.nextInt();
System.out.println("Select a number between 1 & 20");
int nr = milan.nextInt();
if(n <= 20) {
int [] numeros = new int[n];
for(int i = 0; i<numeros.length;i++) {
Arrays.fill(numeros, nr);


}


}else {
System.out.print("size greater than 20, error");
}

milanvirendra
Автор

describe('Solar Heater Application', function() {
let heaterId;
let distributerName = "Harvey Spector"; // Updated name to match the image

it('Allocate Solar Heater', async function() {
// Enter the Distributer Name
await

// Enter the Purchase Date as current date
let currentDate = new Date();
let formattedPurchaseDate = currentDate.toISOString().slice(0, 10);
await

// Enter the Install Date as the 6th day from the Purchase Date
let installDate = new Date();
+ 6);
let formattedInstallDate = installDate.toISOString().slice(0, 10);
await

// Enter the Customer ID as 1002
await

// Check if the Register button is interactable
let registerButton = element(by.cssContainingText('button', 'Register'));


// Click on the Register button
await registerButton.click();

// Extract the message that appears after the button is clicked
let successMessage =


// Place an assertion to validate if the "class" attribute at the message is "xt-success"


// Extract the solar heater number from the message and store it in the variable heaterId
let messageText = await successMessage.getText();
heaterId = messageText.match(/Solar Heater (\d+)/)[1];
});

it('View Bookings', async function() {
// Click on "View Bookings" link
await element(by.linkText('View Bookings')).click();

// Locate the dropdown
let dropdown =

// Collect all the options of the dropdown
let options =

// Iterate through all the options collected and check if any option's text matches the heaterId
let found = false;
await options.each(async function(option) {
let text = await option.getText();
if (text === heaterId) {
found = true;
await option.click();
}
});

// Add a wait statement for 3 seconds
await browser.sleep(3000);

// Place an assertion to validate if the displayed distributor name matches the distributorName
let displayedDistributorName =

});
});

priyankanura
Автор

import java.util.*;

class Check {

public static class Point {
int x;
int y;

Point(int x, int y) {
this.x = x;
this.y = y;
}
}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of the array(Max: 20): ");
int n = sc.nextInt();

while(n <= 0 || n > 20) {
System.out.print("Invalid! Enter again: ");
n = sc.nextInt();
}

Point[] points = new Point[n];
fillArrayOfPoints(points);
printArrayOfPoints(points);
}

private static void fillArrayOfPoints(Point[] points) {
Scanner sc = new Scanner(System.in);

for(int i = 0; i < points.length; i++) {
System.out.print("Enter x and y for Point " + (i + 1) + ": ");
points[i] = new Point(sc.nextInt(), sc.nextInt());
}
}

private static void printArrayOfPoints(Point[] points) {
System.out.print("The points are: ");

for(int i = 0; i < points.length; i++) {
System.out.println("(" + points[i].x + ", " + points[i].y + ")");
}
}
}

suswithcherry