Get Mystery Box with random crypto!

Advance Java 👨‍💻

Logo of telegram channel java_codings — Advance Java 👨‍💻 A
Logo of telegram channel java_codings — Advance Java 👨‍💻
Channel address: @java_codings
Categories: Technologies
Language: English
Subscribers: 12.97K
Description from channel

This channel will serve you all the Codes and Programs of java Programming Language
Contact Admin: @Pravin_Suthar
Youtube channel:
https://www.youtube.com/channel/UCWFwwPMuAx_DY3hi9Tin7gA
Like share and subscribe my channel

Ratings & Reviews

1.33

3 reviews

Reviews can be left only by registered users. All reviews are moderated by admins.

5 stars

0

4 stars

0

3 stars

0

2 stars

1

1 stars

2


The latest Messages 2

2019-09-25 13:30:34 53. Magic Matrix.

import java.io.*;

class MagicMatrix
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the size of the matrix : ");
int n = Integer.parseInt(br.readLine());

if (n > 5)
System.out.println("Enter a number between 1 to 5 ");
else
{
int A[][] = new int[n][n]; // Creating the Magic Matrix
int i, j, k, t;

/*Initializing every cell of the matrix with 0 */
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
A[i][j] = 0;
}
}

/* When the size of the matrix is Odd */
if (n % 2 != 0)
{
i = 0;
j = n / 2;
k = 1;
while (k <= n * n)
{
A[i][j] = k++;
i--; // Making one step upward
j++; // Moving one step to the right

if (i < 0 && j > n - 1) // Condition for the top-right corner element
{
i = i + 2;
j--;
}

if (i < 0) // Wrapping around the row if it goes out of boundary
i = n - 1;

if (j > n - 1) // Wrapping around the column if it goes out of boundary
j = 0;

if (A[i][j] > 0) // Condition when the cell is already filled
{
i = i + 2;
j--;
}
}
}
/* When the size of the matrix is even */
else
{
k = 1;

/* Filling the matrix with natural numbers from 1 till n*n */
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
A[i][j] = k++;
}
}

j = n - 1;

for (i = 0; i < n / 2; i++)
{
/* swapping corner elements of primary diagonal */
t = A[i][i];
A[i][i] = A[j][j];
A[j][j] = t;

/* swapping corner elements of secondary diagonal */
t = A[i][j];
A[i][j] = A[j][i];
A[j][i] = t;

j--;
}
}

/* Printing the Magic matrix */
System.out.println("The Magic Matrix of size " + n + "x" + n + " is:");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
System.out.print(A[i][j] + "\t");
}
System.out.println();
}
}
}
}

@java_codings
8.7K viewsSuthar Pravin, 10:30
Open / Comment
2019-09-25 13:29:02 52. Find closest value of a number in an Array.

import java.util.*;

class ClosestValue
{
public static void main(String[] args)
{
int a[];
int find;
int closest = 0;

Scanner sc = new Scanner(System.in);

System.out.println("Enter size of array");
int size = sc.nextInt();

a = new int[size];

System.out.println("Enter numbers in array");
for (int i = 0; i < size; i++)
{
a[i] = sc.nextInt();
}

System.out.println("Numbers are : ");
for (int i = 0; i < size; i++)
{
System.out.print(a[i] + " ");
}

System.out.println();
System.out.println("Enter Number to find closest value");
find = sc.nextInt();

int distance = Math.abs(closest - find);

for (int i : a)
{
int distanceI = Math.abs(i - find);
if (distance > distanceI)
{
closest = i;
distance = distanceI;
}
}

System.out.println("Closest Value is : " + closest);
}

}

@java_codings
8.0K viewsSuthar Pravin, 10:29
Open / Comment
2019-09-25 13:27:00 51. Example to Pass Arrays to function.

import java.util.*;
class PassingArraystoFunction
{
public static void main(String[] args)
{
int[] a;
int size;

Scanner sc = new Scanner(System.in);

System.out.println("Enter size of array");
size = sc.nextInt();

a = new int[size];

System.out.println("Enter elements in the array");
for(int i = 0 ;i < size; i++)
{
a[i] = sc.nextInt();
}

System.out.println("The Elements of the array are : ");
for(int i = 0 ;i < size; i++)
{
System.out.print(a[i] + " ");
}

//Passing array to the function
addElements(a, size);
}

public static void addElements(int[] a , int size)
{
int sum = 0;

for(int i = 0; i < size; i++)
{
sum += a[i];
}

System.out.println("\nSum of the elements of arrays is : "+sum);
}
}

@java_codings
7.7K viewsSuthar Pravin, 10:27
Open / Comment
2019-09-21 12:06:34 50. Double Matrix.

import java.util.*;
import java.text.DecimalFormat;

class DoubleMatrix
{
public static void main(String[] args)
{
double[][] a;
double[] s;
int row, col, k = 0, i, j;
double sum = 0.0;

DecimalFormat f = new DecimalFormat("##.####");
Scanner sc = new Scanner(System.in);

System.out.println("Enter size of row and column");
row = sc.nextInt();
col = sc.nextInt();

a = new double[row][col];
s = new double[col];

System.out.println("Enter elements of matrix");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
a[i][j] = sc.nextDouble();
}
}

System.out.println("Double Matrix is : ");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
System.out.print(" " + a[i][j]);
}
System.out.println();
}

//sum of the elements of double matrix

for (i = 0; i < col; i++)
{
for (j = 0; j < row; j++)
{
sum = sum + a[j][i];
}
s[k] = sum;
k++;
sum = 0;
}

for (i = 0; i < col; i++)
{
System.out.println("Sum of Column " + (i + 1) + " is : " + f.format(s[i]));
}
}
}

@java_codings
7.4K viewsSuthar Pravin, 09:06
Open / Comment
2019-09-21 12:05:18 49. Display Array using for-each loop.

class DisplayArrayForEach
{
public static void main(String[] args)
{
double[] myList = {1.9, 2.9, 3.4, 3.5};

// Print all the array elements
for (double element : myList)
{
System.out.println(element);
}
}
}

@java_codings
6.9K viewsSuthar Pravin, 09:05
Open / Comment
2019-09-21 12:03:18 48. Create & Display Matrix.

import java.util.Scanner;

class Matrix_Create {

Scanner scan;
int matrix[][];
int row, column;

void create() {

scan = new Scanner(System.in);

System.out.println("Matrix Creation");

System.out.println("\nEnter number of rows :");
row = Integer.parseInt(scan.nextLine());

System.out.println("Enter number of columns :");
column = Integer.parseInt(scan.nextLine());

matrix = new int[row][column];
System.out.println("Enter the data :");

for(int i=0; i
for(int j=0; j

matrix[i][j] =scan.nextInt();
}
}
}

void display() {

System.out.println("\nThe Matrix is :");

for(int i=0; i
for(int j=0; j
System.out.print("\t" + matrix[i][j]);
}
System.out.println();
}
}
}

class CreateAndDisplayMatrix {

public static void main(String
args[]) {

Matrix_Create obj=new Matrix_Create();

obj.create();
obj.display();
}
}

@java_codings
6.9K viewsSuthar Pravin, 09:03
Open / Comment
2019-09-21 12:01:27 47. Basic Array.

import java.util.*;

class ArrayBasic
{
public static void main(String[] args)
{
int[] arr;
int size, i;

Scanner sc = new Scanner(System.in);

System.out.println("Enter size of array");
size = sc.nextInt();

arr = new int[size];

System.out.println("\nEnter array elements");
for (i = 0; i < size; i++)
{
arr[i] = sc.nextInt();
}

System.out.println("\nElements in the Array are : ");
for (i = 0; i < size; i++)
{
System.out.print(arr[i] + " ");
}
}
}

@java_codings
6.6K viewsSuthar Pravin, 09:01
Open / Comment
2019-09-21 12:00:00 46. Array Sum and Average.

import java.io.*;

class ArrayAverage
{
public static void main(String[] args)
{
//define an array
int[] numbers = new int[]{10, 20, 15, 25, 16, 60, 100};

int sum = 0;

for (int i = 0; i < numbers.length; i++)
{
sum = sum + numbers[i];
}

double average = sum / numbers.length;
System.out.println("Sum of array elements is : " + sum);
System.out.println("Average value of array elements is : " + average);
}
}

@java_codings
6.5K viewsSuthar Pravin, 09:00
Open / Comment
2019-09-21 11:58:42 45. Array Sort.

import java.util.Arrays;

class ArraySort
{
// This program is the example of array sorting
public static void main(String[] args)
{
// TODO Auto-generated method stub
// initializing unsorted array
String iArr[] = {"Programming", "Hub", "Alice", "Wonder", "Land"};

// sorting array
Arrays.sort(iArr);

// let us print all the elements available in list
System.out.println("The sorted array is:");
for (int i = 0; i < iArr.length; i++)
{
System.out.println(iArr[i]);
}
}
}

@java_codings
6.3K viewsSuthar Pravin, 08:58
Open / Comment
2019-09-21 11:57:06 44. Array operations.

class ArrayOperations
{
public static void main(String[] args)
{
double[] myList = {1.9, 2.9, 3.4, 3.5};

// Print all the array elements
for (int i = 0; i < myList.length; i++)
{
System.out.println(myList[i] + " ");
}
// Summing all elements
double total = 0;
for (int i = 0; i < myList.length; i++)
{
total += myList[i];
}

System.out.println("Total is " + total);

// Finding the largest element
double max = myList[0];
for (int i = 1; i < myList.length; i++)
{
if (myList[i] > max)
max = myList[i];
}

System.out.println("Max is " + max);
}
}

@java_codings
6.3K viewsSuthar Pravin, edited  08:57
Open / Comment