Professional Documents
Culture Documents
1. Design a Java Program to get ‘n’ unique numbers and then find
the average of those numbers. Print the average and numbers.
CODE:
import java.util.Scanner;
public class QuestionOne {
public static void main(String args[]) {
int n, count = 1;
float x, average, sum = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of n");
n = sc.nextInt();
while (count <= n)
{
System.out.println("Enter the "+count+" number?");
x = sc.nextInt();
sum += x;
++count;
}
average = sum/n;
System.out.println("The Average is"+average);
}
}
OUTPUT:
2. Write a Java program to get m x n matrix as input. Find the count
of odd and even numbers in each row and display it.
CODE:
public class OddEven
{
public static void main(String[] args) {
int rows, cols, countOdd = 0, countEven = 0;
int a[][] = {
{19, 1, 3},
{13, 5, 7},
{8, 21, 16}
};
rows = a.length;
cols = a[0].length;
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
if(a[i][j] % 2 == 0)
countEven++;
else
countOdd++;
}
}
3. Write a Java program to get a string and count the words which
are started with capital letters. Display the result.
CODE:
import java.util.Scanner;
public class QuestionThree{
public static void main(String args[]){
String str;
int upper=0;
Scanner scan=new Scanner(System.in);