Java Tutorial: Practice Questions on Arrays in Java

Java Tutorial: Practice Questions on Arrays in Java

CodeWithHarry

4 года назад

800,494 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@saumyarathi8504
@saumyarathi8504 - 11.09.2024 20:45

jaise string ko reverse kiya waise isko bhi kardete

Ответить
@saumyarathi8504
@saumyarathi8504 - 11.09.2024 21:27

Q6)
public static void main(String[] args) {
int [] arr = {22,3,4,4,555,6,7,89,34,5,};
int GN = arr[0];
for (int element : arr) {
if(element>GN){
GN=element;
}



}System.out.println("Geatest No is "+ GN);
}

Ответить
@saumyarathi8504
@saumyarathi8504 - 11.09.2024 21:30

Q7)
public static void main(String[] args) {
int [] arr = {22,3,4,4,555,6,7,89,34,5,};
int GN = arr[0];
for (int element : arr) {
if(element<GN){
GN=element;
}



}System.out.println("Smallest No is "+ GN);
}

Ответить
@Rajputgaurav0000
@Rajputgaurav0000 - 12.09.2024 08:11

Ye nhi smjh aaya bhai😅

Ответить
@AnasKhan-jm5yr
@AnasKhan-jm5yr - 12.09.2024 22:00

Maza aagya !!😊😊

Ответить
@vrushalimate8691
@vrushalimate8691 - 15.09.2024 10:56

Without using if else, switch case and ternary operator, print three different messages for three different status of paymant.

If status is progress, pending and cancel
How we can achieve this IN JAVA

Ответить
@ASrdp7773
@ASrdp7773 - 15.09.2024 15:13

Reverse an array:- int[]arr={6,5,4,3,2,1};
for(int i=arr.length-1;i>=0;i--)
system.out.pritln(i);

Ответить
@Arshad_mirza007
@Arshad_mirza007 - 16.09.2024 20:31

problem number 5: Reverse an array.
int [] A = {1,2,3,4,5,6};
int i=0 ; int j= A.length-1;
while (i<j){
int temp = A[i];
A[i] = A[j];
A[j] = temp;
i++;j--;
}
System.out.print(Arrays.toString(A));

Ответить
@Anshu_0.7
@Anshu_0.7 - 19.09.2024 16:39

All questions done harry bhai

Ответить
@tempestrexlive6664
@tempestrexlive6664 - 19.09.2024 20:15

was there acrtully a need for floor division

Ответить
@mohit2333
@mohit2333 - 21.09.2024 01:10

int a[]={10,92,54,5,65,787};
int max=Integer.MIN_VALUE;
int min=Integer.MAX_VALUE;
for(int i=0;i<a.length;i++){
if(a[i]>max){
max=a[i];
}
}
System.out.println("the maximum number is " + max);
for(int e:a){
if(e<min){
min=e;
}
}
System.out.println("The minimum number is "+min);

Ответить
@sangharshapawar-themotivat1467
@sangharshapawar-themotivat1467 - 21.09.2024 15:14

// Problem No 1
// Code to print sum of all numbers in an Array
import java.util.Scanner;
class HelloWorld {
public static void main(String[] args) {
int num[]={1,2,3,4,5};
int sum =0;
for(int i=0;i<num.length;i++){
sum = sum+num[i];
}
System.out.println(sum);
}
}

Ответить
@john_wick-v2d
@john_wick-v2d - 21.09.2024 18:10

Maza aagaya Bhaiya

Ответить
@sangharshapawar-themotivat1467
@sangharshapawar-themotivat1467 - 21.09.2024 21:05

// Problem No 4
class Arrays{
public static void main(String args[]){
int mat1[][] = {{1,1,1},
{1,2,3}};
int mat2[][] = {{5,6,7},
{1,2,3}};
int result[][] = {{0,0,0},
{0,0,0}};
for(int i=0;i<mat1.length;i++){
for(int j=0;j<mat1[i].length;j++){
System.out.printf("Set value of i=%d and j=%d \n",i,j);
result[i][j] = mat1[i][j] + mat2[i][j];
}
}
for(int i=0;i<mat1.length;i++){
for(int j=0;j<mat1[i].length;j++){
System.out.print(result[i][j]+ " ");
}
System.out.println(" ");
}
}
}

Ответить
@sangharshapawar-themotivat1467
@sangharshapawar-themotivat1467 - 21.09.2024 21:29

\\problem 6
class Maxnum {
public static void main(String[] args) {
int arr[] = {1,55,67,78,222,56,77};
int max = 0;
for(int e: arr){
if(e>max){
max = e;
}
}
System.out.println(max);
}
}

Ответить
@sangharshapawar-themotivat1467
@sangharshapawar-themotivat1467 - 21.09.2024 21:31

//problem 7
class Minnum {
public static void main(String[] args) {
int arr[] = {1,55,67,78,222,56,77};
int min = 8;
for(int e: arr){
if(e<min){
min = e;
}
}
System.out.println(min);
}
}

Ответить
@sangharshapawar-themotivat1467
@sangharshapawar-themotivat1467 - 21.09.2024 21:52

//problem 8
class Array_Sort {
public static void main(String[] args) {
int arr[] = {1,5,3,4,5,6,7};
boolean issorted = true;
for(int i = 0;i<arr.length-1;i++){
if(arr[i]>arr[i+1]){
issorted = false;
break;
}
}
if(issorted){
System.out.println("Array is Sorted");
}
else{
System.out.println("Array is Not Sorted");
}
}
}

Ответить
@maskedgamer4016W
@maskedgamer4016W - 28.09.2024 17:42

The easier method for Q4. is this: If anyone is willing to:
import java.util.Scanner;
class Practice {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.println("Enter the elements of the first & second array (alternatively).");
int [] [] a = new int [2][3];
int [] [] b = new int [2][3];
int [] [] c = new int [2][3];
for (int i = 0 ; i <2 ; i++)
for (int i1 = 0 ; i1 < 3 ; i1++) {
a[i][i1] = sc.nextInt();
b[i][i1] = sc.nextInt();
c[i][i1] = a[i][i1] + b[i][i1];
}
System.out.println("The sum of the elements of the first 2 arrays is: ");
for (int i = 0 ;i<2;i++)
for (int i1 = 0 ; i1 < 3; i1++)
System.out.println(c[i][i1]);
}
}

Ответить
@TOXIC_SARANSH
@TOXIC_SARANSH - 05.10.2024 09:23

public class MaxMinValue {
public static void main(String[] args) {
int[] numbers = {5, 8, 2, 17, 9, 3};
int max = numbers[0];
int min = numbers[0];

for (int i = 1; i < numbers.length; i++) {
if (numbers[i] > max) {
max = numbers[i];
} else if (numbers[i] < min) {
min = numbers[i];
}
}

System.out.println("Maximum value is: " + max);
System.out.println("Minimum value is: " + min);
}
}

Ответить
@harissatti8790
@harissatti8790 - 05.10.2024 21:26

// Q5:
String [] names = {"Iron","wood", "glass", "stone","gold"};
int j=0;
for(int i=names.length-1; i>=0; i-- , j++){
if(i==j || j>i){
break;
}
String temp;
temp = names[j];
names[j] = names[i];
names[i] = temp;

}
for(int i=0; i<names.length; i++){
System.out.println(names[i]);
}

Ответить
@kingoftherings
@kingoftherings - 07.10.2024 07:37

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

int [] arr = {1, 2, 45, 10, 85};
int n = arr.length;
int temp;
for ( int i = 0; i < n; i++){
temp = arr[i];
int k = n-1-i;
int j = arr[k];
System.out.println(j);
}
}
} @CodeWithHarry Can we use simple code to reverse an array?

Ответить
@humanxai
@humanxai - 08.10.2024 07:13

can we use integer division directly instead of floorDiv?

Ответить
@IncomeIgniters-v5i
@IncomeIgniters-v5i - 08.10.2024 11:26

why not this one to reverse the array
public class reverse {
public static void main(String[] args) {
int [] av = {1,2,3,4,5,6,7};
for(int i = av.length;i>0;i--){
System.out.print(i+" ");
}
}
}

Ответить
@ZubairAkram-w2f
@ZubairAkram-w2f - 10.10.2024 21:28

int[] arr = {1, 2, 3, 4, 5};
int l = arr.length;

for (int i = 0; i < arr.length; i++) {
System.out.print(arr[l - i - 1] + " ");
}
This code actually run which is simple then why you made it complex by swapping it.Any reason? Please Answer.

Ответить
@Emporer_7
@Emporer_7 - 12.10.2024 13:19

Bhai mene pahle problem 5 ne loop meh yee logic use Kiya

for ( i = arr.length-1 ; i > 0 ; i -- )
{
System.out.prinln(arr[i]);
}

Ответить
@ZoraJarvis
@ZoraJarvis - 16.10.2024 20:49

why you're making problem 5 so complicated; it's just a simple program
int arr[] = { 1, 12, 3, 65, 6 };
for (int i = arr.length - 1; i >= 0; i--) {
System.out.println(arr[i]);
}

Ответить
@OjasRawat-v6o
@OjasRawat-v6o - 17.10.2024 19:20

maza aya

Ответить
@prii642
@prii642 - 28.10.2024 20:08

is it enough for practice in array or we have to practice more questions?

Ответить
@PRAKASHCHANDMEENAIIITDharwad
@PRAKASHCHANDMEENAIIITDharwad - 02.11.2024 09:07

superb sir

Ответить
@JahanviGoyal-wx9ni
@JahanviGoyal-wx9ni - 06.11.2024 08:49

Can't we reverse an array by traveling it in the reversing form like : for ( int i = array.length-1; i>0;i--)

Ответить
@neyazkhan9818
@neyazkhan9818 - 11.11.2024 08:58

hlw bro mujhe ye batao aap ye Math.floordiv use kese hua for loop mein please reply

Ответить
@Saahillia
@Saahillia - 13.11.2024 17:55

bhai java ki cheatsheat download nahi kar pa raha hu

Ответить
@biggestcomeback-w8x
@biggestcomeback-w8x - 15.11.2024 10:41

everything is temporary but "right click karke run karna hai" is permananent" and also thanks for your videos .i am currently studying in class 10 and your videos helped me a lot(till video no 66.) in my boards... batch 2024-2025.......love from bihar....

Ответить
@shreydhall34
@shreydhall34 - 17.11.2024 12:25

Can we use ternary operator in Question 2 like this. But it's showing error in code.

// Practice Problem 2
int [] noChk = {85, 90, 55, 68, 97};
System.out.println("Please enter the number you want to find in array: ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
boolean flag = false;
for (int element: noChk){
(num == element)? (flag = true) : (flag = false);
}
if(flag) {
System.out.println("Number " + num + " is present in array.");
} else {
System.out.println("Number " + num + " is not in array.");
}

Ответить
@mrdebu3309
@mrdebu3309 - 27.11.2024 18:01

// Problem 5
public class Exercise_28_Reverse_Array {
public static void main(String[] args) {
int[] ar = { 1, 2, 3, 4 };
int k = 0;
for (int i = 0; i <ar.length; i++) {
for (int j = 0; j < ar.length-i-1; j++) { // Perfrom Swapping and decrese the length of j
k=ar[j];
ar[j]=ar[j+1];
ar[j+1]=k;
}
}
//Print The Array


for (int i = 0; i < ar.length; i++) {
System.out.print(ar[i]);
}
}
}
// Thanks Haryy Boss U are a good teacher but some time make program easier because can't be understandable Big Fan Sir Love U

Ответить
@Shorts_noob1
@Shorts_noob1 - 27.11.2024 21:14

Ye code aap kis app me kartr hai bluej to nahi hai ye bata dijeye app ka name😢

Ответить
@niteshkushwaha8553
@niteshkushwaha8553 - 28.11.2024 10:25

sir i am beginner in programming but your course is too good for understand concept
but i fill i am too late start because currently i am in third year and time is not managed

Ответить
@Beautiful_Princess.
@Beautiful_Princess. - 29.11.2024 15:25

Maza agaya sach men🤩

Ответить
@SKSprg
@SKSprg - 08.12.2024 17:19

Thanku harry bhai
maza aa gaya!!

Ответить
@amareshpradhan1564
@amareshpradhan1564 - 10.12.2024 21:23

Maja aya

Ответить
@BiswamitraMajhi-cg5zk
@BiswamitraMajhi-cg5zk - 12.12.2024 16:54

No sir.....😂😂😂😂😂

Ответить
@CodeBytes_Official
@CodeBytes_Official - 14.12.2024 09:33

PROBLEM 2 -
public class arrayPractice {
public static void main(String[] args) {
float[] num = {6.7f, 7.2f, 7.2f, 8.8f};
float element = 7.8f;

boolean isInArray = false;

for(int i = 0; i<num.length ; i++){
if(element==num[i]){
isInArray = true;
}
}
System.out.println(isInArray);
}
}

Ответить
@gauravijadhav5839
@gauravijadhav5839 - 22.12.2024 17:18

import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
float [] num = {12.3f,1.0f,23.1f,13.4f,12.6f};
for (int i= num.length-1;i>=0;i--){
System.out.println(num[i]);
}
}
}
this is also giving us inverse array then why to do this complication please tell me

Ответить
@CodeBytes_Official
@CodeBytes_Official - 22.12.2024 17:48

// 5 PROGRAM in my way guys-

public class ReverseArray {

public static void main(String[] args) {
int[] arr = {5, 19, 24, 26, 29};
System.out.println("The size of the array: ");
System.out.println(arr.length);

System.out.println("The original array: ");

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

for (int i = 0; i < arr.length / 2; i++) {
int temp = arr[i];
arr[i] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}

System.out.println("\nReversed array:");
for (int i = 0; i<arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}

Ответить
@CodeBytes_Official
@CodeBytes_Official - 22.12.2024 18:28

// 7 PROGRAM to find Minimum element in array -
public class mInElement {
public static void main(String[] args) {
int [] arr = {89, 2, 29, 26, 1212};
int min = arr[0];
for (int i=0; i<arr.length; i++) {
if (arr[i]<min) {
min = arr[i];
}
}
System.out.println("The minimum element is: " + min);

}
}

Ответить
@naveedk.z2144
@naveedk.z2144 - 22.12.2024 22:13

Nice video

Ответить
@naveedk.z2144
@naveedk.z2144 - 23.12.2024 20:59

Nice video for learning java.

Ответить