Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners programes on array
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Amit
programes on array
4 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


a. write a program to find max and min element in an array of an integer b. write a program to convert decimal no. to binary and back to decimal. c. write a program to do following:- i) addition of two matrices ii) subtraction of two matrices iii) multiplication of two matrices iv) find transpose of an matrix


Advertisement
View Answers

March 26, 2011 at 11:10 AM


1)

import java.util.*;
class  ArrayExamples
{
  public static int getMaxValue(int[] arr){
  int maxValue = arr[0];
  for(int i=1;i < arr.length;i++){
    if(arr[i] > maxValue){
      maxValue = arr[i];
    }
  }
  return maxValue;
}

public static int getMinValue(int[] arr){
  int minValue = arr[0];
  for(int i=1;i<arr.length;i++){
    if(arr[i] < minValue){
      minValue = arr[i];
    }
  }
  return minValue;
}
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        System.out.println("Enter Array Elements: ");
        int array[]=new int[5];
        for(int i=0;i<array.length;i++){
            int num=input.nextInt();
            array[i]=num;
        }
        System.out.println("Smallest No: "+getMinValue(array));
        System.out.println("Largest No: "+getMaxValue(array));
    }
}


March 26, 2011 at 11:21 AM


2)

import java.util.*;
class  ArrayExamples
{
  public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        System.out.println("Enter Number: ");
        int number=input.nextInt();
        String binary=Integer.toBinaryString(number);
        System.out.println("Binary: "+binary);
        long num = Long.parseLong(binary);
        long rem;
        while(num > 0){
        rem = num % 10;
        num = num / 10;
        if(rem != 0 && rem != 1){
        System.exit(0);
      }
    }
    int i= Integer.parseInt(binary,2);
    System.out.println("Decimal: "+ i);
    }
}


March 26, 2011 at 11:22 AM


3)

import java.util.*;
class MatrixExamples{

    public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    int[][] A = new int[3][3];
int[][] B = new int[3][3];
int[][] C = new int[3][3];
System.out.println("Enter elements for matrix A : ");
for (int i=0 ; i < A.length ; i++)
for  (int j=0 ; j < A[i].length ; j++){
A[i][j] = input.nextInt();
}
System.out.println("Enter elements for matrix B : ");
for (int i=0 ; i < B.length ; i++)
for  (int j=0 ; j < B[i].length ; j++){
B[i][j] = input.nextInt();
}
System.out.println("Matrix A: ");
        for (int i=0 ; i < A.length ; i++)
        {     System.out.println();
            for  (int j=0 ; j < A[i].length ; j++){
                System.out.print(A[i][j]+" ");
                  }
        }
System.out.println();
System.out.println("Matrix B: ");
        for (int i=0 ; i < B.length ; i++)
        {     System.out.println();
            for  (int j=0 ; j < B[i].length ; j++){
                System.out.print(B[i][j]+" ");
                  }
        }
System.out.println();
int menu = 0;
System.out.println();
System.out.println("1. Addition Of Matrix");
System.out.println("2. Subtraction Of Matrix");
System.out.println("3. Multiplication Of Matrix");
System.out.println("4. Division Of Matrix");
System.out.println("5. Exit");
boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = input.nextInt();
System.out.println();

switch(menu) {
case 1:
    System.out.println("Sum of 2 matrices");
    for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
C[i][j]=A[i][j]+B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println();
}
break;
case 2:
    System.out.println("Subtraction of 2 matrices");
    for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
C[i][j]=A[i][j]-B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println();
}
break;
case 3:
System.out.println("Multiplication of 2 matrices");

for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(+C[i][j]+" ");
}
System.out.println();
} 
break;
case 4:
    System.out.println("Division of 2 matrices : ");
        for(int i = 0; i < 3; i++) {
      for(int j = 0; j < 3; j++) {
      C[i][j]=A[i][j]/B[i][j];
      System.out.print(C[i][j]+" ");
      }
      System.out.println(" ");
      }
case 5:
quit = true;
break;
default:
System.out.println("Invalid Entry!");
 }
}
while (!quit);
}
}


March 26, 2011 at 11:23 AM




Related Tutorials/Questions & Answers:
programes on array
programes on array  a. write a program to find max and min element in an array of an integer b. write a program to convert decimal no. to binary...(System.in); System.out.println("Enter Array Elements: "); int array
programes on strings
programes on strings   a. write a program to copy one array to another array using System.arrayCopy() method. b. write a program to check whether entered string is palindrome or not.   Have a look at the following link
Advertisements
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on methods
programes on methods   write a program to implement bubble sort write a program to demonstrate call by value and call by reference.(pass objects as parameters) write a program to calculate factorial of a no. using recursive
programes on switch
programes on switch   write a program to design menu driven arithmetic calculator write a program to print no of days in a given month   import java.util.*; class Calculator { public static void main(String[] args
programes on if....else
programes on if....else   write a program to check whether entered year is leap year or not write a program to check whether entered no. ends with 5 or not write a program to find minimum of 3 nos using nested if else. write
programes on while loop
programes on while loop   write a program to calculate sum of an entered digit write a program to find gcd and lcm of 2 positive integers   Java sum of digits Java Find LCM and GCD
programes on do... while
programes on do... while   write a program to print reverse of a given digit write a program to check whether entered digit is palindrome or not write a program to check whether entered no. is Armstrong or not   1
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend...(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
Array
Array  How do i insert elements into an array up to a limit from...("Enter Range: "); int size=input.nextInt(); int array[]=new int[size]; System.out.println("Enter Array Elements: "); for(int i=0;i<
array
array  WAP in java to store 6 element in array P and 4 element in array Q. Produce the third arra y R containing all element from p & q
array
array  array memory allocation is dynamic or static in java   Java Arrays have dynamic memory allocation
Array
Array  can we create an array of size 1 lakh in java programming
array
accepts a pointer to integer which represents an array of integer.After that this method prints the entire of the array numbers to the monitor. include using std::cout; using std::endl; void printArray(int *array, int count
array
array  take a 2d array and display all its elements in a matrix fome using only one for loop and ple explain the program in below
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  How to store the results of mysql query in an array... qurey in array: "select distinct(EMPLID)from tblwork where EMPLID not in (select... store the result in array
array
array  wap to calculate reverse of 10 elements in an array?  ...++ ) { arr[i]=input.nextInt(); } System.out.print("Array... reversing, Array is: "); for(int i=arr.length-1;i>=0;i
Array's
Array's  I have to finish an "order page". that checks 2 dropdown boxes and a set of radio buttons and put the results into a set of textboxes, 1 line at a time, then calculate a total. I know I need to create an array, but I'm
 

 

 

DMCA.com