Arrays in Java (Exercise 1)

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ธ.ค. 2024

ความคิดเห็น • 33

  • @thivagarmurugan2955
    @thivagarmurugan2955 2 ปีที่แล้ว +16

    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

  • @mcbotface
    @mcbotface 4 ปีที่แล้ว +10

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

  • @Ceyhus
    @Ceyhus 4 ปีที่แล้ว +3

    Great! Thank you!!!

  • @manognamanu24
    @manognamanu24 4 ปีที่แล้ว +7

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

  • @milanvirendra8881
    @milanvirendra8881 ปีที่แล้ว +1

    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

  • @wesjales5578
    @wesjales5578 9 หลายเดือนก่อน +2

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

  • @kevinbanan
    @kevinbanan 11 หลายเดือนก่อน

    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 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;
    }

  • @acunit5627
    @acunit5627 ปีที่แล้ว +1

    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());
    System.out.println(Arrays.toString(array));

  • @dharavathrajkumar7431
    @dharavathrajkumar7431 10 หลายเดือนก่อน

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

  • @sahayaarulanandageethans5443
    @sahayaarulanandageethans5443 2 ปีที่แล้ว +2

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

  • @lasith123
    @lasith123 3 ปีที่แล้ว +1

    You is the best😘🔥

  • @t.lakshmiprasanna8355
    @t.lakshmiprasanna8355 5 หลายเดือนก่อน

    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

  • @racecarguy21
    @racecarguy21 ปีที่แล้ว

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

  • @kalyansandeep878
    @kalyansandeep878 3 ปีที่แล้ว +1

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

    • @cosmiccreativity7731
      @cosmiccreativity7731 7 หลายเดือนก่อน

      you have to use the loop method then...Otherwise it will not print the elements of the array instead will print the address of the array

  • @cherryblossom4889
    @cherryblossom4889 2 ปีที่แล้ว +2

    Is it possible to solve this without using methods??

  • @manikandana9368
    @manikandana9368 4 ปีที่แล้ว +1

    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?

    • @X_y_zaid
      @X_y_zaid 4 ปีที่แล้ว +5

      You need to import class Point from Package awt

  • @fethiocalan_1
    @fethiocalan_1 ปีที่แล้ว

    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

  • @ferhatf9385
    @ferhatf9385 3 ปีที่แล้ว

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

    • @oyasumi4921
      @oyasumi4921 ปีที่แล้ว

      they can't because if they put greater than 20 ,the program will not execute.

  • @vittalkulkarni2672
    @vittalkulkarni2672 4 ปีที่แล้ว +1

    sir please make videos on vlsi design, electronics

  • @hariharanc8019
    @hariharanc8019 3 ปีที่แล้ว

    Hi, macha kowshik

  • @ramchkaaa7980
    @ramchkaaa7980 ปีที่แล้ว

    r u lebanese?

    • @hassan-p3e
      @hassan-p3e 11 หลายเดือนก่อน

      Eh esmo Ali Badran

  • @priyankanura2355
    @priyankanura2355 7 หลายเดือนก่อน

    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 element(by.model('distributerName')).sendKeys(distributerName);
    // Enter the Purchase Date as current date
    let currentDate = new Date();
    let formattedPurchaseDate = currentDate.toISOString().slice(0, 10);
    await element(by.model('purchaseDate')).sendKeys(formattedPurchaseDate);
    // Enter the Install Date as the 6th day from the Purchase Date
    let installDate = new Date();
    installDate.setDate(currentDate.getDate() + 6);
    let formattedInstallDate = installDate.toISOString().slice(0, 10);
    await element(by.model('installDate')).sendKeys(formattedInstallDate);
    // Enter the Customer ID as 1002
    await element(by.model('customerId')).sendKeys('1002');
    // Check if the Register button is interactable
    let registerButton = element(by.cssContainingText('button', 'Register'));
    expect(registerButton.isEnabled()).toBe(true);
    // Click on the Register button
    await registerButton.click();
    // Extract the message that appears after the button is clicked
    let successMessage = element(by.css('.xt-success'));
    expect(successMessage.isDisplayed()).toBe(true);
    // Place an assertion to validate if the "class" attribute at the message is "xt-success"
    expect(successMessage.getAttribute('class')).toContain('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 = element(by.model('heaterIdDropdown'));
    // Collect all the options of the dropdown
    let options = dropdown.all(by.tagName('option'));
    // 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 = element(by.css('.distributor-name')).getText();
    expect(displayedDistributorName).toEqual(distributerName);
    });
    });

  • @suswithcherry9252
    @suswithcherry9252 11 หลายเดือนก่อน

    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 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 + ")");
    }
    }
    }