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