JAVA3RDEX
JAVA3RDEX
No :
3
Name
: NITHIN ZAHIRUDDIN S.A
Reg. No : 18MIS1106
Programme : M.Tech (SE)
Semester : Fall 2019-20
Course : Programming in Java Lab
Code : SWE1007
Faculty : prof.RAJ KUMAR
Slot : L43+44
1. Create a Java program called ArrayProgram for the following: - declare and create an array newNumbers which
can contain 12 int numbers - assign the following values into newNumbers 10, 6, 88, 91, 25, 77, 14, 23, 4, 235,
66, 81. - find and display the length of the array. - display the value stored in the 5th element of the array. -
change the value in the 5th element to 35. Display again. - calculate and display the average of the values
stored in the array (use the length attribute). - Sort the newNumbers in ascending order. - Search a number
from newNumbers.
Code:
import java.io.*;
class ArrayProgram
int i,j,total=0,temp;
for(i=0;i<arraylength;i++)
total=total+newNumbers[i];
System.out.println("Average is"+avg);
for(i=0;i<arraylength-1;i++)
for(j=0;j<=arraylength-i-1;j++)
if(newNumbers[j]>newNumbers[j+1])
temp=newNumbers[j];
newNumbers[j]=newNumbers[j+1];
newNumbers[j+1]=temp;
}
}
for(i=0;i<arraylength;i++)
System.out.println(newNumbers[i]);
for(i=0;i<arraylength;i++)
if(newNumbers[i]==77)
int position;
position=i-1;
System.out.println("position is"+position);
Output:
2. A mathematician wants to develop an automated program to check the matrix is symmetric or not. He/She
approaches you for the help. Being a programmer, through a java program to fulfill his/her requirement. Example:
AT = A 1 2 3 2 8 4 3 4 9 Note: Read the inputs through keyboard.
Code:
int count=0,i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
a[i][j]=Integer.parseInt(d.readLine()); //conversion
for(i=0;i<3;i++)
for(j=0;j<3;j++)
count=1; //if both the values are not equal then it goes inside the loop and becomes 1
}
}
if(count==0) //if the values are equal while checking using boolean numbers then it prints symmetric
System.out.println("Its symmetric");
else
Output:
3. Develop a String program to find the index position of the following character marked in aeromark: S= “All the
best to you”
Code:
import java.io.*;
class index
int pos=S.indexOf("t");
int pos1=S.indexOf("t",pos+1);
System.out.println(pos1);
Output:
4. Develop a Java program to read ‘n’ strings and sort the strings in ascending order. Note: Read the inputs through
keyboard.
Code:
import java.util.Scanner;
{
public static void main(String[] args)
int n;
String temp;
n = s.nextInt();
System.out.println("Enter strings:");
a[i] = s1.nextLine();
if (a[i].compareTo(a[j])>0)
temp = a[i];
a[i] = a[j];
a[j] = temp;
System.out.print("Sorted Order:");
System.out.print(a[i] + ",");
System.out.print(a[n - 1]);
sir when I retried the same problem online at home ,i was not able to get the ouput. But in class I got the output
sir.i'm unable to find the error in the program.