0% found this document useful (0 votes)
80 views7 pages

Java Prog

The document contains 6 code snippets written in Java that demonstrate various programming concepts: 1) A program to find prime numbers within a given range. 2) A program to check if a string is a palindrome. 3) A program to sort an array of strings alphabetically. 4) A program to multiply two matrices and output the result. 5) A program to input and sum integers in an array. 6) Additional Java code snippets.

Uploaded by

Arun Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views7 pages

Java Prog

The document contains 6 code snippets written in Java that demonstrate various programming concepts: 1) A program to find prime numbers within a given range. 2) A program to check if a string is a palindrome. 3) A program to sort an array of strings alphabetically. 4) A program to multiply two matrices and output the result. 5) A program to input and sum integers in an array. 6) Additional Java code snippets.

Uploaded by

Arun Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

2nd question

import [Link].*; import [Link].*; import [Link].*; class prime { public static void main(String ar[]) { int i,j; Scanner h=new Scanner([Link]); [Link]("enter the value of n"); int num=[Link](); [Link]("Prime number:"); for(i=1;i<=num;i++) { for(j=2;j<i;j++) { int n=i%j; if(n==0) { break; } } if(i==j) { [Link]("the prime no. is"+i); }

} } }

3rd question
import [Link].*; import [Link].*; class palindrome { public static void main(String ar[]) { Scanner h=new Scanner([Link]); String s=[Link]();

String s2=new StringBuffer(s).reverse().toString(); if([Link](s2)) { [Link]("the string is palindrome"); } else { [Link]("the string is not a palindrome"); }

} }

4th question
import [Link].*; import [Link].*; class sortng { public static void main(String ar[]) { Scanner h=new Scanner([Link]); [Link]("enter value of n"); int n=[Link](); String temp=new String(); String names[]=new String[n+1]; for(int i=0;i<=n;i++) { names[i]=[Link](); } for(int i=0;i<=n;i++) { for(int j=i+1;j<=n;j++) { if(names[i].compareTo(names[j])>0) { temp=names[i]; names[i]=names[j];

names[j]=temp; } } } [Link]("the sorted oreder is"); for(int i=0;i<=n;i++) { [Link](names[i]); } } }

5th question
import [Link].*; import [Link].*; class mul { public static void main(String ar[]) { Scanner h=new Scanner([Link]); [Link]("enter the row"); int n=[Link](); [Link]("enter the col"); int m=[Link](); int a[][]=new int[50][50]; int b[][]=new int[50][50]; int c[][]=new int[50][50]; [Link]("reading the mat1");

for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { a[i][j]=[Link](); }

6th question
import [Link].*; import [Link].*; class array { public static void main(String ar[]) { int sum=0; Scanner h=new Scanner([Link]); int s[]=new int[10]; for(int i=0;i<10;i++) { s[i]=[Link](); sum=sum+s[i]; [Link](s[i]); [Link]("the sum is"+sum); } }

} [Link]("reading the mat2"); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { b[i][j]=[Link](); } } [Link]("the mul mat is "); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { c[i][j]=0; for(int k=0;k<n;k++) { c[i][j]=c[i][j]+(a[i][k]*b[k][j]); } [Link](c[i][j]); } } } }

You might also like