Computer Assignmen1
Computer Assignmen1
Computer Assignmen1
1) import java.util.*;
class Marks{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
System.out.println("Enter the number of students");
int n=in.nextInt();
int roll[]=new int[n];
double m1[]=new double[n];
double m2[]=new double[n];
double m3[]=new double[n];
String name[]=new String[n];
for(int i=0;i<n;i++){
System.out.println("Enter the roll numbers,name and marks in 3
subjects for"+(i+1)+"student");
roll[i]=in.nextInt();
name[i]=in.next();
m1[i]=in.nextDouble();
m2[i]=in.nextDouble();
m3[i]=in.nextDouble();
double avg=(m1[i]+m2[i]+m3[i])/3.0;
if(avg>=85&&avg<=100){
System.out.println("EXCELLENT");
}
else if(avg>=75&&avg<=84){
System.out.println("DISTINCTION");
}
else if(avg>=60&&avg<=74){
System.out.println("FIRST CLASS");
}
else if(avg>=40&&avg<=59){
System.out.println("PASS");
}
else{
System.out.println("POOR");
}
}
}
}
2) import java.util.*;
class Cities{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
String cities[]=new String[10];
int std[]=new int[10];
for(int i=0;i<10;i++){
System.out.println("Enter city:");
cities[i]=in.next();
System.out.print("Enter std code:");
std[i]=in.nextInt();
}
System.out.println("Enter city name to search:");
String target=in.next();
boolean searchSuccessful=false;
for(int i=0;i<10;i++){
if(cities[i].equals(target)){
System.out.println("Search successful");
System.out.println("City:"+cities[i]);
System.out.println("STD code:"+std[i]);
searchSuccessful=true;
break;
}
}
if(!searchSuccessful){
System.out.println("Search unsuccessful,No such city in the list");
}
}
}
3) import java.util.*;
class BinarySearch{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int[] m={5,7,9,11,15,20,30,45,89,97};
int i,ub=9,lb=0,p,f=0,ns;
System.out.println("Enter the number to be searched");
ns=in.nextInt();
for(i=0;i<10;i++){
p=(ub+lb)/2;
if(m[p]>ns){
lb=p+1;
}
else if(m[p]<ns){
ub=p-1;
}
if(m[p]==ns){
f++;
break;
}
if(f==1){
System.out.println(ns+"found at index"+ i);
}
else{
System.out.println("Search element not found");
}
}
}
}
4) import java.util.*;
class Max_Min{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
System.out.println("Enter numbers");
int a[]=new int[20];
for(int i=0;i<20;i++){
a[i]=in.nextInt();
}
int max=a[0];
int min=a[0];
int sum=0;
for(int i=0;i<20;i++){
if(a[i]>max){
max=a[i];
}
else if(a[i]<min){
min=a[i];
}
sum=sum+a[i];
}
System.out.println("Largest number is"+max);
System.out.println("Smallest number is"+min);
System.out.println("sum is"+sum);
}
}
5) import java.util.*;
class TotalMarks{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int n;
System.out.println("Enter number of students");
n=in.nextInt();
String name[]=new String[n];
double marks[]=new double[n];
double ave,total=0.0;
for(int i=0;i<n;i++){
System.out.println("Enter name and total marks");
name[i]=in.nextLine();
marks[i]=in.nextDouble();
total=total+marks[i];
}
ave=total/n;
System.out.println("Name " + " "+"Deviation");
for(int i=0;i<n;i++){
System.out.println(name[i]+""+(marks[i]-ave));
}
}
}
6) import java.util.*;
class Input{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
System.out.println("Enter any 20 letters");
int vc=0,cc=0;
for(int i=1;i<=20;i++){
char ch=in.next().charAt(0);
if(Character.isUpperCase(ch)==true){
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'){
vc++;
}
else{
cc++;
}
}
else{
ch=Character.toUpperCase(ch);
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'){
vc++;
}
else{
cc++;
}
}
}
System.out.println("Number of Vowels = " + vc);
System.out.println("Number of Consonants = " + cc);
}
}
7) import java.util.*;
class Wonders{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
String wonders[]={"CHICHEN ITZA","CHRIST THE REDEEMER","TAJ
MAHAL","GREAT WALL OF CHINA","MACHU PICHU","PETRA","COLOSSEUM"};
String
locations[]={"MEXICO","BRAZIL","INDIA","CHINA","PERU","JORDAN","ITALY"};
System.out.print("Enter country:");
String c=in.nextLine();
int i;
for(i=0;i<locations.length;i++){
if(locations[i].equals(c)){
System.out.println(locations[i]+"-"+wonders[i]);
break;
}
}
if(i==locations.length){
System.out.println("Sorry not found");
}
}
}
8) import java.util.*;
class Square{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int m[]=new int[10];
int arr[]=new int[10];
System.out.println("Enter the numbers in the array");
for(int i=0;i<10;i++){
m[i]=in.nextInt();
}
System.out.println("The squared array is:");
for(int i=0;i<10;i++){
arr[i]=m[i]*m[i];
System.out.println(arr[i]+"");
}
}
}
9) import java.util.*;
class NaturalSum{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int m[]=new int[76];
for(int i=0;i<76;i++){
m[i]= i;
}
int sum=0;
for(int i=0;i<76;i++){
sum=sum+m[i];
}
System.out.println("The sum of the first 75 natural numbers are"+sum);
}
}
}
}
class FrequencyVowels{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
String st;
System.out.println("Enter new string");
int n[]=new int[5];
for(int i=0;i<5;i++){
n[i]=0;
}
int num=0;
st=in.next();
int s=st.length();
System.out.println(s);
for(int i=0;i<s;i++){
if(st.charAt(i)=='a'){
n[0]++;
}
else if(st.charAt(i)=='e'){
n[1]++;
}
else if(st.charAt(i)=='i'){
n[2]++;
}
else if(st.charAt(i)=='o'){
n[3]++;
}
else if(st.charAt(i)=='u'){
n[4]++;
}
num=n[0]+n[1]+n[2]+n[3]+n[4];
System.out.println("No. of a" + n[0]);
System.out.println("No. of e" + n[1]);
System.out.println("No. of i" + n[2]);
System.out.println("No. of o" + n[3]);
System.out.println("No. of u" + n[4]);
System.out.println("Total number of vowels="+num);
}
}
}
12) import java.util.*;
class PosNeg{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int m[]=new int[20];
int min=m[0],max=m[0],p=0,n=0;
System.out.println("Enter the numbers in the array");
for(int i=0;i<20;i++){
m[i]=in.nextInt();
}
for(int i=0;i<20;i++){
if(min>m[i]){
min=m[i];
}
if(max<m[i]){
max=m[i];
}
if(m[i]>0){
p++;
}
else if(m[i]<0){
n++;
}
}
System.out.println("The smallest number is="+min);
System.out.println("The largest number is="+max);
System.out.println("Negative numbers are"+n);
System.out.println("Positive numbers are"+p);
}
}
class OddEvenSum
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}
class PrimeNumber
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}
System.out.println("Prime Numbers:");
for (int i = 0; i < arr.length; i++) {
int c = 0;
for (int j = 1; j <= arr[i]; j++) {
if (arr[i] % j == 0) {
c++;
}
}
if (c == 2)
System.out.print(arr[i] + ", ");
}
}
}
class Highest
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter 20 numbers:");
for (i = 0; i < 20; i++) {
arr[i] = in.nextInt();
}
int en = 0, on = 0;
for (i = 0; i < 20; i++) {
if (arr[i] % 2 == 0)
even[en++] = arr[i];
else
odd[on++] = arr[i];
}
System.out.println("Even Numbers:");
for (i = 0; i < en; i++) {
System.out.print(even[i] + " ");
}
System.out.println("Odd Numbers:");
for (i = 0; i < on; i++) {
System.out.print(odd[i] + " ");
}
}
}
System.out.println("Enter 20 numbers");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}
class Student
{
public static void main(String args[]) {
System.out.println("Truncated numbers");
for (int i = 0; i < b.length; i++) {
System.out.print(b[i] + ", ");
}
}
}
class StudentsMarks
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
i = 0;
while(i < P.length) {
R[i] = P[i];
i++;
}
int j = 0;
while(j < Q.length) {
R[i++] = Q[j++];
}
int l=0,h=9,k=0;
while (l <= h) {
int m = (l + h) / 2;
if (n[m] == year) {
k++;
break;
}
else if (n[m] < year) {
l = m + 1;
}
else {
h = m - 1;
}
}
if (k == 1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}
System.out.println("Roll No\tName\tRemark");
for (int i = 0; i < n; i++) {
String remark;
if (avg[i] < 40)
remark = "Poor";
else if (avg[i] < 60)
remark = "Pass";
else if (avg[i] < 75)
remark = "First Class";
else if (avg[i] < 85)
remark = "Distinction";
else
remark = "Excellent";
System.out.println(rollNo[i] + "\t" + name[i] + "\t" + remark);
}
}
}