Комментарии:
jaise string ko reverse kiya waise isko bhi kardete
Ответить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);
}
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);
}
Ye nhi smjh aaya bhai😅
ОтветитьMaza aagya !!😊😊
Ответить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
Reverse an array:- int[]arr={6,5,4,3,2,1};
for(int i=arr.length-1;i>=0;i--)
system.out.pritln(i);
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));
All questions done harry bhai
Ответитьwas there acrtully a need for floor division
Ответить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);
// 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);
}
}
Maza aagaya Bhaiya
Ответить// 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(" ");
}
}
}
\\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);
}
}
//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);
}
}
//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");
}
}
}
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]);
}
}
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);
}
}
// 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]);
}
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?
can we use integer division directly instead of floorDiv?
Ответить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+" ");
}
}
}
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.
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]);
}
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]);
}
maza aya
Ответитьis it enough for practice in array or we have to practice more questions?
ОтветитьCan't we reverse an array by traveling it in the reversing form like : for ( int i = array.length-1; i>0;i--)
Ответитьhlw bro mujhe ye batao aap ye Math.floordiv use kese hua for loop mein please reply
Ответитьbhai java ki cheatsheat download nahi kar pa raha hu
Ответить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....
Ответить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.");
}
// 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
Ye code aap kis app me kartr hai bluej to nahi hai ye bata dijeye app ka name😢
Ответить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
Maza agaya sach men🤩
ОтветитьThanku harry bhai
maza aa gaya!!
Maja aya
ОтветитьNo sir.....😂😂😂😂😂
Ответить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);
}
}
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
// 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] + " ");
}
}
}
// 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);
}
}
Nice video
ОтветитьNice video for learning java.
Ответить