0% found this document useful (0 votes)
19 views9 pages

Nothing

Uploaded by

sahaneishaan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views9 pages

Nothing

Uploaded by

sahaneishaan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Q11] import java.util.

Scanner;

public class KboatVowelRemoval


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a word or sentence:");
String str = in.nextLine();

int len = str.length();


String newStr = "";

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

char ch = Character.toUpperCase(str.charAt(i));

if (ch == 'A' ||
ch == 'E' ||
ch == 'I' ||
ch == 'O' ||
ch == 'U') {
continue;
}

newStr = newStr + ch;


}
System.out.println("String with vowels removed");
System.out.println(newStr);
}
}
Q12]
import java.util.Scanner;

public class KboatSurnameFirst


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a name of 3 words:");
String name = in.nextLine();

/*
* Get the last index
* of space in the string
*/
int lastSpaceIdx = name.lastIndexOf(' ');

String surname = name.substring(lastSpaceIdx + 1);


String initialName = name.substring(0, lastSpaceIdx);

System.out.println(surname + " " + initialName);


}
Q13]
import java.util.Scanner;

public class Caseconvert


{
private String str;
private String convStr;

public void getstr() {


Scanner in = new Scanner(System.in);
System.out.print("Enter the string: ");
str = in.nextLine();
}

public void convert() {


char arr[] = new char[str.length()];
for (int i = 0; i < str.length(); i++) {
if (Character.isUpperCase(str.charAt(i)))
arr[i] = Character.toLowerCase(str.charAt(i));
else if (Character.isLowerCase(str.charAt(i)))
arr[i] = Character.toUpperCase(str.charAt(i));
else
arr[i] = str.charAt(i);
}
convStr = new String(arr);
}

public void display() {


System.out.println("Converted String:");
System.out.println(convStr);
}

public static void main(String args[]) {


Caseconvert obj = new Caseconvert();
obj.getstr();
obj.convert();
obj.display();
}
Q14] (REFER SCHOOL NOTES)

Q15] (REFER SCHOOL NOTES)


Q16] (REFER SCHOOL NOTES)
Q17]
import java.util.Scanner;

public class KboatSDAMarks


{
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 for " + name[i] + " = "
+ (totalmarks[i] - avg));
}
}
}
Q18]
import java.util.Scanner;

public class KboatSDABubbleSort


{
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();
}

//Sort first half in ascending order


for (int i = 0; i < arr.length / 2 - 1; i++) {
for (int j = 0; j < arr.length / 2 - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int t = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = t;
}
}
}

//Sort second half in descending order


for (int i = 0; i < arr.length / 2 - 1; i++) {
for (int j = arr.length / 2; j < arr.length - i - 1; j++) {
if (arr[j] < arr[j + 1]) {
int t = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = t;
}
}
}

//Print the final sorted array


System.out.println("\nSorted Array:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
Q19]
import java.util.Scanner;

public class KboatStudent


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

Scanner in = new Scanner(System.in);


int studentDetails[] = new int[200]; //40 * 5 = 200

System.out.println("Enter student details");


for (int i = 0, idx = 1; i < 200; i = i + 5, idx++) {
System.out.print("Student " + idx + " roll number: ");
studentDetails[i] = in.nextInt();
System.out.print("Student " + idx + " English Marks: ");
studentDetails[i+1] = in.nextInt();
System.out.print("Student " + idx + " Maths Marks: ");
studentDetails[i+2] = in.nextInt();
System.out.print("Student " + idx + " Physics Marks: ");
studentDetails[i+3] = in.nextInt();
System.out.print("Student " + idx + " Chemistry Marks: ");
studentDetails[i+4] = in.nextInt();
}
for (int i = 0; i < 200; i = i + 5) {
System.out.println("Roll No: " + studentDetails[i]);
if (studentDetails[i+1] > 34 &&
((studentDetails[i+2] > 34 && studentDetails[i+3] > 34) ||
(studentDetails[i+2] > 34 && studentDetails[i+4] > 34) ||
(studentDetails[i+3] > 34 && studentDetails[i+4] > 34))) {
System.out.println("Promotion is granted.");
}
else {
System.out.println("Promotion is not granted.");
}
}

Q20] (REFER SCHOOL NOTES)

You might also like