0% found this document useful (0 votes)
169 views40 pages

Java ISC Class 11/12: 100 Programs

The document contains a series of Java programming assignments for ISC Class 11/12, covering topics such as arrays, constructors, methods, and strings. Each question includes a Java program with its corresponding output, demonstrating various programming concepts like finding the largest element in an array, creating a student class, checking for prime numbers, and counting vowels in a string. The assignments are structured to provide practical coding experience for students.

Uploaded by

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

Java ISC Class 11/12: 100 Programs

The document contains a series of Java programming assignments for ISC Class 11/12, covering topics such as arrays, constructors, methods, and strings. Each question includes a Java program with its corresponding output, demonstrating various programming concepts like finding the largest element in an array, creating a student class, checking for prime numbers, and counting vowels in a string. The assignments are structured to provide practical coding experience for students.

Uploaded by

dead46492
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Programs: 100 Simple ISC Class 11/12

Assignments (Arrays, Constructors, Methods, Strings)

Question 1: Write a Java program to find the largest element in an integer array.
Program:
class Q1 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 2: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q2 {
String name; int roll;
Q2(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q2 s = new Q2("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 3: Write a method to check if a number is prime and use it in main.


Program:
class Q3 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 4: Count vowels in a given string.


Program:
class Q4 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 5: Write a Java program to find the largest element in an integer array.
Program:
class Q5 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19
Question 6: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q6 {
String name; int roll;
Q6(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q6 s = new Q6("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 7: Write a method to check if a number is prime and use it in main.


Program:
class Q7 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 8: Count vowels in a given string.


Program:
class Q8 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 9: Write a Java program to find the largest element in an integer array.
Program:
class Q9 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 10: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q10 {
String name; int roll;
Q10(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q10 s = new Q10("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21
Question 11: Write a method to check if a number is prime and use it in main.
Program:
class Q11 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 12: Count vowels in a given string.


Program:
class Q12 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 13: Write a Java program to find the largest element in an integer array.
Program:
class Q13 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 14: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q14 {
String name; int roll;
Q14(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q14 s = new Q14("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 15: Write a method to check if a number is prime and use it in main.
Program:
class Q15 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true
Question 16: Count vowels in a given string.
Program:
class Q16 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 17: Write a Java program to find the largest element in an integer array.
Program:
class Q17 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 18: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q18 {
String name; int roll;
Q18(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q18 s = new Q18("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 19: Write a method to check if a number is prime and use it in main.
Program:
class Q19 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 20: Count vowels in a given string.


Program:
class Q20 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3
Question 21: Write a Java program to find the largest element in an integer array.
Program:
class Q21 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 22: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q22 {
String name; int roll;
Q22(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q22 s = new Q22("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 23: Write a method to check if a number is prime and use it in main.
Program:
class Q23 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 24: Count vowels in a given string.


Program:
class Q24 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 25: Write a Java program to find the largest element in an integer array.
Program:
class Q25 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19
Question 26: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q26 {
String name; int roll;
Q26(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q26 s = new Q26("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 27: Write a method to check if a number is prime and use it in main.
Program:
class Q27 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 28: Count vowels in a given string.


Program:
class Q28 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 29: Write a Java program to find the largest element in an integer array.
Program:
class Q29 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 30: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q30 {
String name; int roll;
Q30(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q30 s = new Q30("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21
Question 31: Write a method to check if a number is prime and use it in main.
Program:
class Q31 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 32: Count vowels in a given string.


Program:
class Q32 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 33: Write a Java program to find the largest element in an integer array.
Program:
class Q33 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 34: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q34 {
String name; int roll;
Q34(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q34 s = new Q34("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 35: Write a method to check if a number is prime and use it in main.
Program:
class Q35 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true
Question 36: Count vowels in a given string.
Program:
class Q36 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 37: Write a Java program to find the largest element in an integer array.
Program:
class Q37 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 38: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q38 {
String name; int roll;
Q38(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q38 s = new Q38("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 39: Write a method to check if a number is prime and use it in main.
Program:
class Q39 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 40: Count vowels in a given string.


Program:
class Q40 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3
Question 41: Write a Java program to find the largest element in an integer array.
Program:
class Q41 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 42: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q42 {
String name; int roll;
Q42(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q42 s = new Q42("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 43: Write a method to check if a number is prime and use it in main.
Program:
class Q43 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 44: Count vowels in a given string.


Program:
class Q44 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 45: Write a Java program to find the largest element in an integer array.
Program:
class Q45 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19
Question 46: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q46 {
String name; int roll;
Q46(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q46 s = new Q46("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 47: Write a method to check if a number is prime and use it in main.
Program:
class Q47 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 48: Count vowels in a given string.


Program:
class Q48 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 49: Write a Java program to find the largest element in an integer array.
Program:
class Q49 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 50: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q50 {
String name; int roll;
Q50(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q50 s = new Q50("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21
Question 51: Write a method to check if a number is prime and use it in main.
Program:
class Q51 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 52: Count vowels in a given string.


Program:
class Q52 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 53: Write a Java program to find the largest element in an integer array.
Program:
class Q53 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 54: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q54 {
String name; int roll;
Q54(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q54 s = new Q54("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 55: Write a method to check if a number is prime and use it in main.
Program:
class Q55 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true
Question 56: Count vowels in a given string.
Program:
class Q56 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 57: Write a Java program to find the largest element in an integer array.
Program:
class Q57 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 58: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q58 {
String name; int roll;
Q58(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q58 s = new Q58("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 59: Write a method to check if a number is prime and use it in main.
Program:
class Q59 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 60: Count vowels in a given string.


Program:
class Q60 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3
Question 61: Write a Java program to find the largest element in an integer array.
Program:
class Q61 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 62: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q62 {
String name; int roll;
Q62(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q62 s = new Q62("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 63: Write a method to check if a number is prime and use it in main.
Program:
class Q63 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 64: Count vowels in a given string.


Program:
class Q64 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 65: Write a Java program to find the largest element in an integer array.
Program:
class Q65 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19
Question 66: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q66 {
String name; int roll;
Q66(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q66 s = new Q66("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 67: Write a method to check if a number is prime and use it in main.
Program:
class Q67 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 68: Count vowels in a given string.


Program:
class Q68 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 69: Write a Java program to find the largest element in an integer array.
Program:
class Q69 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 70: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q70 {
String name; int roll;
Q70(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q70 s = new Q70("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21
Question 71: Write a method to check if a number is prime and use it in main.
Program:
class Q71 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 72: Count vowels in a given string.


Program:
class Q72 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 73: Write a Java program to find the largest element in an integer array.
Program:
class Q73 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 74: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q74 {
String name; int roll;
Q74(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q74 s = new Q74("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 75: Write a method to check if a number is prime and use it in main.
Program:
class Q75 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true
Question 76: Count vowels in a given string.
Program:
class Q76 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 77: Write a Java program to find the largest element in an integer array.
Program:
class Q77 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 78: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q78 {
String name; int roll;
Q78(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q78 s = new Q78("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 79: Write a method to check if a number is prime and use it in main.
Program:
class Q79 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 80: Count vowels in a given string.


Program:
class Q80 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3
Question 81: Write a Java program to find the largest element in an integer array.
Program:
class Q81 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 82: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q82 {
String name; int roll;
Q82(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q82 s = new Q82("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 83: Write a method to check if a number is prime and use it in main.
Program:
class Q83 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 84: Count vowels in a given string.


Program:
class Q84 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 85: Write a Java program to find the largest element in an integer array.
Program:
class Q85 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19
Question 86: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q86 {
String name; int roll;
Q86(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q86 s = new Q86("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 87: Write a method to check if a number is prime and use it in main.
Program:
class Q87 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 88: Count vowels in a given string.


Program:
class Q88 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 89: Write a Java program to find the largest element in an integer array.
Program:
class Q89 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 90: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q90 {
String name; int roll;
Q90(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q90 s = new Q90("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21
Question 91: Write a method to check if a number is prime and use it in main.
Program:
class Q91 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 92: Count vowels in a given string.


Program:
class Q92 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 93: Write a Java program to find the largest element in an integer array.
Program:
class Q93 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 94: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q94 {
String name; int roll;
Q94(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q94 s = new Q94("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 95: Write a method to check if a number is prime and use it in main.
Program:
class Q95 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true
Question 96: Count vowels in a given string.
Program:
class Q96 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Question 97: Write a Java program to find the largest element in an integer array.
Program:
class Q97 {
public static void main(String[] args) {
int[] a = {5, 12, 3, 19, 7}; // sample array
int max = a[0]; // initialize max
for(int i=1;i<[Link];i++)
if(a[i] > max) max = a[i];
[Link](max); // output largest
}
}
Output: 19

Question 98: Create a class Student with a constructor that sets name and roll. Print details.
Program:
class Q98 {
String name; int roll;
Q98(String name, int roll) { // constructor
[Link] = name; [Link] = roll;
}
public static void main(String[] args) {
Q98 s = new Q98("Anil", 21);
[Link]([Link] + " " + [Link]);
}
}
Output: Anil 21

Question 99: Write a method to check if a number is prime and use it in main.
Program:
class Q99 {
static boolean isPrime(int x) {
if(x<2) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
public static void main(String[] args) {
[Link](isPrime(29)); // true
}
}
Output: true

Question 100: Count vowels in a given string.


Program:
class Q100 {
public static void main(String[] args) {
String s = "Hello World";
int c=0;
for(char ch: [Link]().toCharArray())
if("aeiou".indexOf(ch) >= 0) c++;
[Link](c);
}
}
Output: 3

Common questions

Powered by AI

The 'isPrime' method is used to determine whether a given number is a prime number. It returns false if the number is less than 2, and checks divisibility from 2 up to the square root of the number. If any divisor is found, it returns false; otherwise, it returns true .

The 'Student' class can be extended by adding more attributes such as 'grade' or 'major', and methods like 'getDetails()' to return a formatted string, or 'updateRoll()' to change the roll number. Overriding the toString() method for better object descriptions is another enhancement .

A class named 'Student' is created with two fields 'name' and 'roll.' A constructor is defined to initialize these fields with given parameters. An object of this class is instantiated with specific arguments, and its details are printed using System.out.println .

The method optimizes by only checking divisibility up to the square root because a larger factor of x must be a multiple of a smaller factor that has already been checked. This reduces the number of checks significantly, improving efficiency .

The Java program converts the input string to lowercase, iterates over each character, and checks if the character is a vowel using the "aeiou" string. The indexOf method is used to determine if the character is a vowel and increments a counter each time a vowel is found .

The program initializes the largest element with the first element of the array and iterates through the rest of the elements. It compares each element to the current largest and updates the largest element if a larger value is found .

If the initial largest element is not set correctly, the algorithm might incorrectly identify the largest element. For instance, starting with zero or an incorrect value could lead to overlooking higher elements, especially if all array elements are less than an incorrect starting value .

Converting a string to lowercase ensures uniformity when comparing characters, as it eliminates mismatches due to differences in case between vowels in the string and the reference string used for comparison .

To count both uppercase and lowercase vowels, modify the program to create a string that includes both 'aeiou' and 'AEIOU'. Use this string with the indexOf method to check for vowel occurrence without converting the original string to lowercase .

Modifying the loop structure could lead to performance issues or incorrect results. Unintended changes in indices could skip potential divisors, or make the algorithm unnecessarily complex without improving efficiency, thereby leading to errors or longer execution times .

You might also like