Array Programs SDA
Array Programs SDA
It is a structure which can hold a number of values of the same data type having same variable
name with different subscripts. It is also called as subscripted variable. It is a composite data
type. It is two types SDA and DDA.
In array the elements are stored in contiguous memory location with an index number where
the index number begins with 0.
Advantages of array:
- Random Access
- Code Optimization
Disadvantages of array:
- Size Limit: We can store a fixed no. of elements in array
n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]
WAP to accept 10 numbers and store in a SDA. Display the array elements along with the
sum of all the numbers
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 numbers”);
int n[] = new int[10];
int s=0;
for(int i=0; i<10; i++)
{
n[i] = sc.nextInt();
s = s+n[i];
}
System.out.println(“Array elements are:”);
for(int i=0; i<10; i++)
System.out.print(n[i] + “\t”);
System.out.println(“\n Sum of numbers=”+s);
}
}
WAP to accept 10 numbers and store in a SDA. Display the array elements along with the
sum of all even numbers and all odd numbers.
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 numbers”);
int n[] = new int[10];
int ev=0, od=0;
for(int i=0; i<10; i++)
{
n[i] = sc.nextInt();
if(n[i]%2==0)
ev = ev+n[i];
else
od = od+n[i];
}
System.out.println(“Array elements are:”);
for(int i=0; i<10; i++)
System.out.print(n[i] + “\t”);
System.out.println(“\n Sum of all even nos=”+ev);
System.out.println(“Sum of all odd nos =”+od);
}
}
WAP to accept 20 numbers and store in a single dimensional array. Display the sum of all the
numbers which are divisible by 3 or 5.
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int s=0;
int arr[] = new int[20];
System.out.println(“Enter 20 numbers”);
for(int i=0; i<20; i++)
{
arr[i] = sc.nextInt();
if(arr[i]%3==0 || arr[i]%5==0)
s = s+arr[i];
}
System.out.println(“Sum of all numbers those are divisible by 3 or 5 : ”+s);
}
}
WAP to accept 10 numbers and store in a single dimensional array. Display all the buzz
numbers of the array
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int arr[] = new int[10];
System.out.println(“Enter 10 numbers”);
for(int i=0; i<10; i++)
arr[i] = sc.nextInt();
System.out.println(“All the buzz numbers are:”);
for(int i=0; i<10; i++)
{
if(arr[i]%7==0 || arr[i]%10==7)
System.out.print(arr[i] + “,”);
}
}
}
WAP to accept 10 numbers and store in a single dimensional array. Display all the perfect
square numbers of the array
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 numbers”);
int n[] = new int[10];
for(int i=0; i<10; i++)
n[i] = sc.nextInt();
System.out.println(“All the Perfect Square numbers are”);
for(int i=0; i<10; i++)
{
int p = (int)Math.sqrt(n[i]);
if(p*p == n[i])
System.out.print(n[i]+ “,”);
}
}
}
WAP to accept 10 numbers and store in a single dimensional array. Display all the perfect
cube numbers of the array
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 numbers”);
int n[] = new int[10];
for(int i=0; i<10; i++)
n[i] = sc.nextInt();
System.out.println(“All the Perfect Cube numbers are”);
for(int i=0; i<10; i++)
{
int p = (int)Math.cbrt(n[i]);
if(p*p*p == n[i])
System.out.print(n[i]+ “,”);
}
}
}
WAP to accept and store 10 nos in a SDA. Find and display the highest and lowest number
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 numbers”);
int n[] = new int[10];
for(int i=0; i<10; i++)
n[i] = sc.nextInt();
int h = n[0], s = n[0];
for(int i=0; i<10; i++)
{
if(n[i]>h)
h = n[i];
if(n[i]<s)
s = n[i];
}
System.out.println(“Highest Number=”+h);
System.out.println(“Lowest Number =”+s);
}
}
WAP to accept and store 15 numbers and store in a SDA. Now display those numbers which
ends with 0. Also display the count of the numbers which ends with 0
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 15 numbers”);
int n[] = new int[15];
for(int i=0; i<15; i++)
n[i] = sc.nextInt();
int c = 0;
System.out.println(“List of nos that ends with 0”);
for(int i=0; i<15; i++)
{
if(n[i]%10 == 0)
{
System.out.print(n[i]+ “\t”);
c++;
}
}
System.out.println(“Count of numbers that ends with zero = ”+c);
}
}
WAP to accept 10 numbers and store in a SDA. Display the only the even nos
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 numbers”);
int n[] = new int[10];
for(int i=0; i<10; i++)
n[i] = sc.nextInt();
System.out.println(“All the even nos are:”);
for(int i=0; i<10; i++)
{
if(n[i]%2==0)
System.out.print(n[i] + “\t”);
}
}
}
WAP to accept 10 country name and mortality rate and store in two different SDAs. Now
display that country name and its mortality rate whose mortality rate is highest
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 country names”);
String cn[] = new String[10];
for(int i=0; i<10; i++)
cn[i] = sc.nextLine();
System.out.println(“Enter mortality rates of 10 countries”);
double mr[] = new double[10];
for(int i=0; i<10; i++)
mr[i] = sc.nextDouble();
int p=mr[0], pos=0;
for(int i=0; i<10; i++)
{
if(mr[i]>p)
{
pos = i;
p = mr[i];
}
}
System.out.println(“Country details with highest mortality rate”);
System.out.println(cn[pos]+ “\t” + mr[pos]);
}
}
WAP to accept 10 names and their marks in two SDAs. Now display the name and the mark
of those students who have scored above average.
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter mark and name of 10 students”);
double m[] = new double[10];
String n[] = new String[10];
double sum=0.0, avg;
for(int i=0; i<10; i++)
{
m[i] = sc.nextDouble();
n[i] = sc.nextLine();
sum = sum+m[i];
}
avg = sum/10;
System.out.println(“Name and mark of students those have scored above
average”);
for(int i=0; i<10; i++)
{
if(m[i]>avg)
System.out.println(n[i]+ “\t” + m[i]);
}
}
}
Define a class to declare a character array of size 10, accept the characters into the array.
Display the characters with highest and lowest ASCII
Example:
R, z, q, A, N, p, m, U, Q, F
Output:
Characters with highest ASCII value = z
Characters with lowest ASCII value = A
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 characters”);
char arr[] = new char[10];
for(int i=0; i<10; i++)
arr[i] = sc.next().charAt(0);
char h=arr[0], s=arr[0];
for(int i=1; i<10; i++)
{
if(arr[i]>h)
h = arr[i];
if(arr[i]<s)
s = arr[i];
}
System.out.println(“The characters with highest ASCII Value ”+h);
System.out.println(“The characters with lowest ASCII Value ”+s);
}
}
Define a class to declare an array of size 20 of double data type, accept the elements into the
array and perform the following
Calculate and print the product of all elements
Print the square of each element of the array
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 20 numbers”);
double arr[] = new double[20];
double p = 1.0;
for(int i=0; i<20; i++)
{
arr[i] = sc.nextDouble();
p = p*arr[i];
}
System.out.println(“Product of all elements =”+p);
System.out.println(“Square of each element of array”);
for(int i=0; i<20; i++)
System.out.println(arr[i]*arr[i]);
}
}
Define a class to declare an array to accept and store 10 words. Display only those words
which begin with the letter ‘A’ or ‘a’ and also end with ‘A’ or ‘a’
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 words”);
String s[] = new String[10];
for(int i=0; i<10 ; i++)
s[i] = sc.next();
System.out.println(“The words that starts and ends with A or a”)
for(int i=0; i<10; i++)
{
String s1 = s[i].toUpperCase();
if(s1.startsWith(“A”) && s1.endsWith(“A”))
System.out.println(s[i]);
}
}
}
WAP to accept 10 words and store in a SDA. Now display those words whose length is even
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 words”);
String s[] = new String[10];
for(int i=0; i<10; i++)
s[i] = sc.next();
System.out.println(“The words with even length”);
for(int i=0; i<10; i++)
{
if(s[i].length()%2==0)
System.out.println(s[i]);
}
}
}
WAP to accept name and their total mark of 10 students in two different SDAs. Display the
name along with their marks those have scored above average.
WAP to accept 10 characters and store in a SDA. Now display the sum of ASCII values of all
the characters, sum of ASCII values (even) of the characters, sum of ASCII values (odd) of the
characters.
WAP to accept 10 characters and store in a SDA. Now display those characters whose ASCII
value is even
WAP to accept 10 words and store in a SDA. Now display the word with highest frequency
along with the frequency
Frequency of a word is the sum of ASCII value of all the characters of the word
Example: ABC (Frequency = 65+66+67 = 198)
WAP to accept and store 10 characters in a SDA. Now display the count of letters, digits and
special symbols
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char ch[] = new char[10];
System.out.println(“Enter 10 characters”);
int L=0, D=0, SS=0;
for(int i=0; i<10; i++)
{
ch[i] = sc.next().charAt(0);
if(Character.isLetter(ch[i])==true)
L++;
else if(Character.isDigit(ch[i])==true)
D++;
else
SS++;
}
System.out.println(“No. of Letters = ”+L);
System.out.println(“No. of Digits = ”+D);
System.out.println(“No. of Special Symbols = ”+SS);
}
}
WAP to accept and store 10 characters in a SDA. Now display the count of uppercase letters
and lowercase letters
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char ch[] = new char[10];
System.out.println(“Enter 10 characters”);
int UL=0, LL=0;
for(int i=0; i<10; i++)
{
ch[i] = sc.next().charAt(0);
if(Character.isUpperCase(ch[i])==true)
UL++;
if(Character.isLowerCase(ch[i])==true)
LL++;
}
System.out.println(“No. of UpperCase Letters = ”+UL);
System.out.println(“No. of LowerCase Letters = ”+LL);
}
}
WAP to accept and store 10 characters in a SDA. Now display the count of vowels and
consonants
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char ch[] = new char[10];
System.out.println(“Enter 10 characters”);
int v=0, c=0; String vo = “AEIOUaeiou”;
for(int i=0; i<10; i++)
{
ch[i] = sc.next().charAt(0);
if(Character.isLetter(ch[i])==true)
{
if(vo.indexOf(ch[i])>=0)
v++;
else
c++;
}
}
System.out.println(“No. of Vowels = ”+v);
System.out.println(“No. of Consonants = ”+c);
}
}
WAP to accept and store 10 characters. Now display the count of consonants
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char ch[] = new char[10];
System.out.println(“Enter 10 characters”);
int c=0; String v = “AEIOUaeiou”;
for(int i=0; i<10; i++)
{
ch[i] = sc.next().charAt(0);
if(Character.isLetter(ch[i])==true)
{
if(v.indexOf(ch[i])==-1)
c++;
}
}
System.out.println(“No. of Consonants = ”+c);
}
}
WAP to accept and store 10 characters in a SDA. Now display the sum of ASCII values, the
character with highest ASCII value and the character with lowest ASCII Value
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char ch[] = new char[10];
System.out.println(“Enter 10 characters”);
char h=ch[0], s=ch[0];
int sum = 0;
for(int i=0; i<10; i++)
{
ch[i] = sc.next().charAt(0);
sum = sum+(int)ch[i];
if((int)ch[i]>(int)h)
h = ch[i];
if((int)ch[i]<(int)h)
s = ch[i];
}
System.out.println(“Sum of ASCII Value = ”+sum);
System.out.println(“Character with highest ASCII Value = ”+h);
System.out.println(“Character with lowest ASCII Value = ”+s);
}
}
WAP to accept and store 10 characters in a SDA. Display the sum of even ASCII values and
sum of odd ASCII values
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char ch[] = new char[10];
System.out.println(“Enter 10 characters”);
int ev=0, od=0;
for(int i=0; i<10; i++)
{
ch[i] = sc.next().charAt(0);
if((int)ch[i]%2==0)
ev = ev+(int)ch[i];
else
od = od+(int)ch[i];
}
System.out.println(“Sum of Even ASCII Value = ”+ev);
System.out.println(“Sum of Odd ASCII Value = ”+od);
}
}
WAP to accept 10 names and store in a SDA. Now display the longest and shortest string
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 names”);
String n[] = new String[10];
for(int i=0; i<10; i++)
n[i] = sc.next();
String h = n[0], s = n[0];
for(int i=0; i<10; i++)
{
if(n[i].length()>h.length())
h = n[i];
if(n[i].length()<s.length())
s = n[i];
}
System.out.println(“Longest string =”+h);
System.out.println(“Shortest string =”+s);
}
}
WAP to accept 10 names and store in a SDA. Now display the names that start with vowel
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 names”);
String n[] = new String[10];
for(int i=0; i<10; i++)
n[i] = sc.next();
char ch; String v = “AEIOUaeiou”;
for(int i=0; i<10; i++)
{
ch = Character.toUpperCase(n[i].charAt(0));
if(v.indexOf(ch)>=0)
System.out.println(n[i]);
}
}
}
WAP to accept 10 names and store in a SDA. Now display the names that end with
consonant
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 names”);
String n[] = new String[10];
for(int i=0; i<10; i++)
n[i] = sc.next();
char ch; String v = “AEIOUaeiou”;
for(int i=0; i<10; i++)
{
ch = Character.toUpperCase (n[i].charAt (n[i].length()-1));
if(v.indexOf(ch)==-1)
System.out.println(n[i]);
}
}
}
Searching:
It is the process of finding an element in array
There are two types of searching like:
1. Linear Search
2. Binary Search
Linear Search/Sequential Search
In this searching technique every item of the array is checked sequentially and if a match is
found then the particular item is returned otherwise the search continues till the end of the
array
It can search the item both in sorted array as well as unsorted array.
WAP to accept and store 10 numbers in a SDA. Now accept a number from user and search
in array. If found display the message “Search Successful. Number is found”, otherwise
display the message “Search Unsuccessful” using Linear Search technique
import java.util.*;
public class array_search
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int n[] = new int[10];
System.out.println(“Enter 10 numbers”);
for(int i=0; i<10; i++)
n[i] = sc.nextInt();
System.out.println(“Enter a number to search”);
int num = sc.nextInt();
int flag=0;
for(int i=0; i<10; i++)
{
if(n[i]==num)
{
System.out.println(“Search Successful. Number is found”);
flag=1;
break;
}
}
if(flag==0)
System.out.println(“Search Unsuccessful”);
}
}
WAP to accept and store 10 names in a SDA. Now accept a name from user and search in
array. If found display the found name along with the message “Search Successful. Name is
found”, otherwise display the message “Search Unsuccessful” using Linear Search technique
import java.util.*;
public class array_search
{
public static void main()
{
Scanner sc = new Scanner(System.in);
String n[] = new String[10];
System.out.println(“Enter 10 names”);
for(int i=0; i<10; i++)
n[i] = sc.next ();
System.out.println(“Enter a name to search”);
String nm = sc.next();
int flag=0;
for(int i=0; i<10; i++)
{
if(n[i].equals(nm))
{
System.out.println(nm);
System.out.println(“Search Successful. Name is found”);
flag=1;
break;
}
}
if(flag==0)
System.out.println(“Search Unsuccessful”);
}
}
Disadvantages:
This process is time consuming when the array size is larger
WAP to accept and store 10 country names and their capital in two SDAs. Now accept a
country name from user and search in array. If found display the country along with its
capital. Also display the message “Search Successful”, otherwise display the message
“Search Unsuccessful” using Linear Search technique
import java.util.*;
public class array_search
{
public static void main()
{
Scanner sc = new Scanner(System.in);
String cn[] = new String[10];
String cp[] = new String[10];
System.out.println(“Enter 10 country names and their capital”);
for(int i=0; i<10; i++)
{
cn[i] = sc.nextLine();
cp[i] = sc.nextLine();
}
System.out.println(“Enter a country name to search”);
String nm = sc.nextLine();
int flag=0;
for(int i=0; i<10; i++)
{
if(cn[i].equals(nm))
{
System.out.println(cn[i] + “\t” + cp[i]);
System.out.println(“Search Successful”);
flag=1;
break;
}
}
if(flag==0)
System.out.println(“Search Unsuccessful”);
}
}
Binary Search:
In this searching technique the whole array is divided into two parts and the item is searched
in either halves. This process continues till the number is found otherwise till the end of the
array.
WAP to accept and store 10 numbers in a SDA. Now accept a number from user and search
in array. If found display the message “Search Successful. Number is found”, otherwise
display the message “Search Unsuccessful” using Binary Search technique
import java.util.*;
public class array_search
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int n[] = new int[10];
System.out.println(“Enter 10 numbers”);
for(int i=0; i<10; i++)
n[i] = sc.nextInt();
int L = 0, U = 9, mid;
System.out.println(“Enter a number to search”);
int num = sc.nextInt();
int flag=0;
while(L<=U)
{
mid = (L+U)/2;
if(num>n[mid])
L = mid+1;
else if(num<n[mid])
U = mid-1;
else
{
System.out.println(“Search Successful. Number is found”);
flag=1;
break;
}
}
if(flag==0)
System.out.println(“Search Unsuccessful”);
}
}
Character Array
Display
Count of Letters, count of digits, count special symbols
Count of Uppercase Letters, Count of lower case letters,
Count of vowels, count of consonants
WAP to accept and store 10 characters in a SDA. Now display the count of special symbols
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char ch[] = new char[10];
System.out.println(“Enter 10 characters”);
int c = 0;
for(int i=0; i<10; i++)
{
ch[i] = sc.next().charAt(0);
if(Character.isLetterOrDigit(ch[i]) == false)
c++;
}
System.out.println(“No. of Special Symbols = ”+c);
}
}
Display only the letters of array, display only the digits, display only the special symbols,
display the upper case letters, display the lower case letters, display the vowels, display the
consonants
Display only the letters of array
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char ch[] = new char[10];
System.out.println(“Enter 10 characters”);
for(int i=0; i<10; i++)
ch[i] = sc.next().charAt(0);
System.out.println(“All the letters are”);
for(int i=0; i<10; i++)
{
if(Character.isLetter(ch[i]==true)
System.out.print(ch[i] + “\t”);
}
}
}
WAP to accept and store 10 characters in a SDA. Now display each character with their
respective ASCII Codes
import java.util.*;
public class array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char ch[] = new char[10];
System.out.println(“Enter 10 characters”);
for(int i=0; i<10; i++)
ch[i] = sc.next().charAt(0);
System.out.println(“Characters and their ASCII”);
for(int i=0; i<10; i++)
System.out.println(ch[i] + “\t” + (int)ch[i]);
}
}
Sorting: This is the process of arranging data in an array either in ascending order or
descending order.
Bubble Sort: In this sorting technique array is traversed from first element to last element and
two consecutive elements are compared. If the current element is greater than the next
element, it is swapped
WAP to accept 10 numbers and store in a SDA. Now sort the array in ascending order using
bubble sort technique.
import java.util.*;
class BubbleSort
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 numbers”);
int arr[] = new int[10];
for(int i=0; i<10; i++)
arr[i] = sc.nextInt();
for(int i=0; i<9; i++) //outer loop 0 to <size-1
{
for(int j=0; j<9-i; j++) //inner loop 0 to <size-1-i
{
if(arr[j]>arr[j+1])// > sign for ascending and < for descending
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
System.out.println("Array after sorting in ascending order");
for(int i=0; i<10; i++)
System.out.print(arr[i]+",");
}
}
WAP to accept 10 numbers and store in a SDA. Now sort the array in descending order using
bubble sort technique.
import java.util.*;
class BubbleSort
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 numbers”);
int arr[] = new int[10];
for(int i=0; i<10; i++)
arr[i] = sc.nextInt();
for(int i=0; i<9; i++)
{
for(int j=0; j<9-i; j++)
{
if(arr[j]<arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
System.out.println("Array after sorting in descending order");
for(int i=0; i<10; i++)
System.out.print(arr[i]+",");
}
}
WAP to accept 10 names and store in a SDA. Now sort the array in ascending order using
bubble sort technique. Display the original array and sorted array
import java.util.*;
class BubbleSort
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 names”);
String arr[] = new String[10];
for(int i=0; i<10; i++)
arr[i] = sc.next();
WAP to accept 10 names and store in a SDA. Now sort the array in descending order using
bubble sort technique. Display the original array and sorted array
import java.util.*;
class BubbleSort
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 names”);
String arr[] = new String[10];
for(int i=0; i<10; i++)
arr[i] = sc.next();
length length()
This is used to find the length of an This is used to find the length of a string
array
It is a variable It is a method
int arr[] = {31, 36, 45, 50, 60, 75, 86, 90} ;
for(int i=0; i<arr.length; i++)
1. System.out.println(arr[4].substring(0,2)+arr[5].substring(4,6));
Ans: TATA
2. System.out.println(arr[5].indexOf(‘O’)+arr[4].lastIndexOf(‘A’));
Ans: 4
3. System.out.println(arr[2].length()+ “” +arr[7].length());
Ans: 46
4. System.out.println(arr[8].charAt(3)+arr[0].charAt(2));
Ans: 160
5. System.out.println(arr[8].charAt(3)+ “”+arr[0].charAt(2));
Ans: NR
6. System.out.println(arr[1].compareTo(arr[5]);
Ans: - 18
String arr[] = { “FORD”, “BMW”, “AUDI”, “SKODA”, “TATA”, “TOYOTA”, “TESLA”, “800”, “489”,
“375”};
1. System.out.println(Integer.parseInt(arr[7])+arr[0].charAt(0)+arr[9]);
Ans: 870375
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 numbers”);
int n[] = new int[10];
for(int i=0; i<10; i++)
n[i] = sc.nextInt(();
for(int i=0; i<10; i++)
if(n[i]<0)
System.out.print(n[i]+ “,”);
System.out.println(“Enter roll number and name of 100 students along with the
marks scored in six subjects”);
for(int i=0; i<100; i++)
{
rn[i] = sc.nextInt();
n[i] = sc.next();
s1[i] = sc.nextInt();
s2[i] = sc.nextInt();
s3[i] = sc.nextInt();
s4[i] = sc.nextInt();
s5[i] = sc.nextInt();
s6[i] = sc.nextInt();
}
System.out.println(“Percentage \t Grade”);
double p; String g;
for(int i=0; i<100; i++)
{
p = (s1[i]+s2[i]+s3[i]+s4[i]+s5[i]+s6[i])/6.0;
if(p>=80 && p<=100)
g = “A”;
else if(p>=60 && p<80)
g = “B”;
else if(p>=40 && p<60)
g = “C”;
else
g = “D”;
System.out.println(p + “\t” + g);
}
}
}
import java.util.*;
class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 20 nos”);
int arr[] = new int[20];
for(int i=0; i<20; i++)
arr[i] = sc.nextInt();
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int rn[] = new int[40];
int e[] = new int[40];
int p[] = new int[40];
int c[] = new int[40];
int m[] = new int[40];
System.out.println(“Enter roll number and marks of English, physics, chemistry,
maths of 40 students”);
for(int i=0; i<40; i++)
{
rn[i] = sc.nextInt();
e[i] = sc.nextInt();
p[i] = sc.nextInt();
c[i] = sc.nextInt();
m[i] = sc.nextInt();
}
System.out.println(“Roll No \t Status”);
for(int i=0; i<40; i++)
{
if(e[i]>=35)
{
if((p[i]>=35 && c[i]>=35) || (p[i]>=35 && m[i]>=35) || (c[i]>=35 &&
m[i]>=35))
System.out.println(rn[i]+ “\t Promotion Granted”);
else
System.out.println(rn[i]+ “\t Promotion not granted”);
}
else
System.out.println(rn[i]+ “\t Promotion not granted”);
}
}
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int rn[] = new int[50];
int sa[] = new int[50];
int sb[] = new int[50];
int sc[] = new int[50];
double avg[] = new double[50];
System.out.println(“Enter roll no, marks of 3 subjects of 50 students”);
for(int i=0; i<50; i++)
{
rn[i] = sc.nextInt();
sa[i] = sc.nextInt();
sb[i] = sc.nextInt();
sc[i] = sc.nextInt();
avg[i] = (sa[i]+sb[i]+sc[i])/3.0;
}
System.out.println(“Average of each student”);
for(int i=0; i<50; i++)
System.out.println(avg[i]);
System.out.println(“Roll NO and Average marks of the students whose average is
above 80”);
for(int i=0; i<50; i++)
{
if(avg[i]>80)
System.out.println(rn[i]+ “\t” + avg[i]);
}
System.out.println(“Roll NO and Average marks of the students whose average is
below 80”);
for(int i=0; i<50; i++)
{
if(avg[i]<80)
System.out.println(rn[i]+ “\t” + avg[i]);
}
}
}
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int P[] = new int[6];
int Q[] = new int[4];
int R[] = new int[10];
System.out.println(“Enter 6 integers”);
for(int i=0; i<6; i++)
P[i] = sc.nextInt();
System.out.println(“Enter 4 integers”);
for(int i=0; i<4; i++)
Q[i] = sc.nextInt();
int i;
for(i = 0; i<P.length; i++)
R[i] = P[i];
System.out.println(“Merged Array”);
for(int i=0; i<R.length; i++)
System.out.println(R[i]);
}
}
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int Y[] = {1982,1987,1993,1996,1999,2003,2006,2007, 2009,2010};
System.out.println(“Enter year of graduation”);
int year = sc.nextInt();
int L=0, U=9, mid, flag=0;
while(L<=U)
{
mid = (L+U)/2;
if(year>Y[mid])
L = mid+1;
else if(year<Y[mid])
U = mid-1;
else
{
flag=1;
System.out.println(“Record exists”);
break;
}
}
if(flag==0)
System.out.println(“Record does not exist”);
}
}
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter no. of students”);
int n = sc.nextInt();
int rn[] = new int[n];
int sa[] = new int[n];
int sb[] = new int[n];
int sc[] = new int[n];
String nm[] = new String[n];
String rem[] = new String[n];
double avg[] = new double[n];
System.out.println(“Enter roll no, marks of 3 subjects and names of ”+n+ “
students”);
for(int i=0; i<n; i++)
{
rn[i] = sc.nextInt();
sa[i] = sc.nextInt();
sb[i] = sc.nextInt();
sc[i] = sc.nextInt();
nm[i] = sc.next();
avg[i] = (sa[i]+sb[i]+sc[i])/3.0;
if(avg[i]>=85 && avg[i]<=100)
rem[i] = “Excellent”;
else if(avg[i]>=75 && avg[i]<=84)
rem[i] = “Distinction”;
else if(avg[i]>=60 && avg[i]<=74)
rem[i] = “First Class”;
else if(avg[i]>=40 && avg[i]<=59)
rem[i] = “Pass”;
else
rem[i] = “Poor”;
}
System.out.println(“Remarks”);
for(int i=0; i<n; i++)
System.out.println(rn[i]+ “\t”+nm[i]+ “\t”+rem[i]);
}
}
import java.util.*;
public class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 20 numbers”);
double n[] = new double[20];
for(int i=0; i<20; i++)
n[i] = sc.nextDouble();
double h=n[0], s= n[0];
for(int i=0; i<10; i++)
{
if(n[i]>h)
h = n[i];
if(n[i]<s)
s = n[i];
}
System.out.println(“Range of the array = ”+(h-s));
}
}