You are on page 1of 10

Assingment – 7 [pronic number ]

import java.util.Scanner;

public class pronic {

public static boolean isPronic(int number) {

int i = 0; // iterator variable

// loop until square root of the number

while(i <= (int)Math.sqrt(number)) {

if(number == i*(i+1))

return true;

// increase iterator variable by 1

i++;

return false;

public static void main(String[] args) {

// declare variables
int number = 0;

// read the input

Scanner scan = new Scanner(System.in);

System.out.print("Enter an integer number:: ");

number = scan.nextInt();

// check the number is Pronic number or not

if(isPronic(number))

System.out.println(number+" is a"

+ " pronic number");

else

System.out.println(number+" is not a"

+ " pronic number");

}
Assignment 8

import java.util.Scanner;

public class overld


{
double area(double a, double b, double c) {
double s = (a + b + c) / 2;
double x = s * (s-a) * (s-b) * (s-c);
double result = Math.sqrt(x);
return result;
}

double area (int a, int b, int height) {


double result = (1.0 / 2.0) * height * (a + b);
return result;
}

double area (double diagonal1, double diagonal2) {


double result = 1.0 / 2.0 * diagonal1 * diagonal2;
return result;
}
}

Assignment – 10

public class oveld_2


{
void check (String str , char ch ) {
int count = 0;
int len = str.length();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (ch == c) {
count++;
}
}
System.out.println("Frequency of " + ch + " = " + count);
}

void check(String s1) {


String s2 = s1.toLowerCase();
int len = s2.length();
System.out.println("Vowels:");
for (int i = 0; i < len; i++) {
char ch = s2.charAt(i);
if (ch == 'a' ||
ch == 'e' ||
ch == 'i' ||
ch == 'o' ||
ch == 'u')
System.out.print(ch + " ");
}
}
}

Assignment – 11

import java.util.Scanner;

public class load_2


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of students: ");
int n = in.nextInt();

String name[] = new String[n];


int totalmarks[] = new int[n];
int grandTotal = 0;

for (int i = 0; i < n; i++) {


in.nextLine();
System.out.print("Enter name of student " + (i+1) + ": ");
name[i] = in.nextLine();
System.out.print("Enter total marks of student " + (i+1) + ": ");
totalmarks[i] = in.nextInt();
grandTotal += totalmarks[i];
}

double avg = grandTotal / (double)n;


System.out.println("Average = " + avg);

for (int i = 0; i < n; i++) {


System.out.println("Deviation of Student " + name[i] + " = "
+ (totalmarks[i] - avg));
}
}
}
Assignment – 12

import java.util.Scanner;

public class load_4


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n[] = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010};

System.out.print("Enter graduation year to search: ");


int year = in.nextInt();

int l = 0, h = n.length - 1, idx = -1;


while (l <= h) {
int m = (l + h) / 2;
if (n[m] == year) {
idx = m;
break;
}
else if (n[m] < year) {
l = m + 1;
}
else {
h = m - 1;
}
}

if (idx == -1)
System.out.println("Yes! Record does not exist");
else
System.out.println("Record exists");
}
}
Assignment 13

import java.util.Scanner;

public class load_67


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);

int P[] = new int[6];


int Q[] = new int[4];
int R[] = new int[10];
int i = 0;

System.out.println("Please Enter 6 elements of array P:");


for (i = 0; i < P.length; i++) {
P[i] = in.nextInt();
}

System.out.println("Enter 4 elements of array Q:");


for (i = 0; i < Q.length; i++) {
Q[i] = in.nextInt();
}

i = 0;
while(i < P.length) {
R[i] = P[i];
i++;
}

int j = 0;
while(j < Q.length) {
R[i++] = Q[j++];
}

System.out.println("Elements of Array R are:");


for (i = 0; i < R.length; i++) {
System.out.print(R[i] + " ");
}
}
}
Assignment 14

import java.util.*;

class Frequency

public static void main(String arr[])

char ch;

String str;

Scanner sc=new Scanner(System.in);

System.out.println("Enter any String ");

str=sc.nextLine();

str=str.toUpperCase();
System.out.println("CHARACTER\tFREQUENCY");

for(ch='A';ch<='Z';ch++)

int count=0;

for(int a=0;a<str.length();a++)

if(str.charAt(a)==ch)

count++;

if(count>0)

{
System.out.println(ch+"\t\t"+count);

Assignment 15

import java.util.Scanner;

public class KboatFilepathSplit


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter full path: ");
String filepath = in.next();

char pathSep = '\\';


char dotSep = '.';

int pathSepIdx = filepath.lastIndexOf(pathSep);


System.out.println("Path:\t\t" + filepath.substring(0, pathSepIdx));

int dotIdx = filepath.lastIndexOf(dotSep);


System.out.println("File Name:\t" + filepath.substring(pathSepIdx + 1,
dotIdx));

System.out.println("Extension:\t" + filepath.substring(dotIdx + 1));


}
}

You might also like