26. Write a program in java to input twelve integers in three rows and four columns. Calculate and print sum of each column?

class SumColumn {                 public static void main(String args[])                 {                                 int i,j,s=0;                                 int n[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};                                 for(i=0;i<4;i++)                                 {                                                 s=0;                                                 for(j=0;j<3;j++)                                                                 s+=n[j][i];                                                 System.out.println((i+1)+" Column Sum : "+s);                                 }                 } }

Advertisements

25. Write a program in java to input nine integers in three rows and three columns. Calculate and print sum of each row?

class SumRow {                 public static void main(String args[])                 {                                 int i,j,s=0;                                 int n[][]={{1,2,3},{4,5,6},{7,8,9}};                                 for(i=0;i<3;i++)                                                 {                                                 s=0;                                                 for(j=0;j<3;j++)                                                                 s+=n[i][j];                                                 System.out.println((i+1)+" Rows Sum : "+s);                                                 }                 } }

24. An example of the two-dimensional array is as fallows –

class Table {                 public static void main(String args[])                 {                                 int i,j;                                 int n[][]={{4,3,2},{9,13,15}};                                 for(i=0;i<2;i++)                                                 for(j=0;j<3;j++)                                                                 System.out.println(n[i][j]);                 } }

23. Write a program in java to input 10 integer number in an array including both negative and positive integer. Restore only positive number in separate array. Arrange and print only positive integer in descending order?

import java.io.DataInputStream; class Descending {                 public static void main(String args[])                 {                                 DataInputStream in=new DataInputStream(System.in);                                 int n[],d[],i,j,k=0,t;                                 n=new int[10];                                 d=new int[10];                                 try                                 {                                                 System.out.println("Enter Ten Integer Number (Negative and Positive) : ");                                                 for(i=0;i<10;i++)                                                                 n[i]=Integer.parseInt(in.readLine());                                                 for(i=0;i<10;i++)                                                                 if(n[i]>=0)                                                                 {                                                                                 d[k]=n[i];                                                                                 k++;                                                                ... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: