0% found this document useful (0 votes)
8 views15 pages

Class Viva

The document contains multiple Java classes, each implementing different functionalities such as finding palindromes, calculating student marks, generating patterns, and performing set operations on strings and arrays. Each class has a main method that allows user interaction through the console for data input and output. The code demonstrates various programming concepts including loops, conditionals, and methods.

Uploaded by

meenu gupta
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)
8 views15 pages

Class Viva

The document contains multiple Java classes, each implementing different functionalities such as finding palindromes, calculating student marks, generating patterns, and performing set operations on strings and arrays. Each class has a main method that allows user interaction through the console for data input and output. The code demonstrates various programming concepts including loops, conditionals, and methods.

Uploaded by

meenu gupta
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
You are on page 1/ 15

class Q1

public static void main()

int r;

System.out.println(“palindrome are”);

for(int x=101;x<10000;x++)

int q=x;int p=0;

while(q>0)

r=q%10;

p=p*10+r;

q=q/10;

if (x==p)

System.out.println(x);

import java.util.*;

class Q2

{
public String name; double mm,me,mh,sum,sum1,avg;

void accept()

Scanner sc=new Scanner(System.in);

System.out.print("Enter name");

name=sc.nextLine();

System.out.print("Enter marks in maths");

mm=sc.nextDouble();

System.out.print("Enter marks in english");

me=sc.nextDouble();

System.out.print("Enter marks in hindi");

mh=sc.nextDouble();

void compute()

double min=Math.min(mm,me);

min=Math.min(min,mh);

sum=mm+me+mh;

sum1=sum-min;

avg=sum/2;

void display()

System.out.println("Name="+name);

System.out.println("Marks in Maths="+mm);

System.out.println("Marks in English="+me);

System.out.println("Marks in Hindi="+mh);
System.out.println("Total Marks="+sum);

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

public static void main()

Viva a=new Viva();

a.accept();

a.compute();

a.display();

class Q3

public static void main()

for(int x=1;x<=5;x++)

for(int y=5;y>=x;y--)

System.out.print("*");

System.out.println("");

for(int x=1;x<=5;x++)

{
for(int y=1;y<=x;y++)

System.out.print("*");

System.out.println("");

import java.util.*;

class Q4

public static String a,b;

void intersection()

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

char ch=a.charAt(x);

if(b.contains(ch+""))

System.out.print(ch);

System.out.println("");

void notinB()
{

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

char ch=a.charAt(x);

if(b.contains(ch+"")==false)

System.out.print(ch);

System.out.println("");

void notinA()

for(int x=0;x<b.length();x++)

char ch=b.charAt(x);

if(a.contains(ch+"")==false)

System.out.print(ch);

System.out.println("");

void union()

{
String con=a.concat(b);

System.out.print(con);

public static void main()

Scanner sc=new Scanner(System.in);

System.out.println("Enter 1st string");

a=sc.nextLine();

System.out.println("Enter 2nd string");

b=sc.nextLine();

Viva c=new Viva();

System.out.println("intersection");

c.intersection();

System.out.println("not in b is");

c.notinB();

System.out.println("not in a is");

c.notinA();

System.out.println("union is");

c.union();

import java.util.*;
class Q5

public static void main()

Scanner sc=new Scanner(System.in);

System.out.println(“Enter string”);

String s=sc.nextLine();

System.out.println(“Palindrome are”);

for(int x=3;x<=s.length();x++)

for(int y=0;y<=s.length()-x;y++)

String s1=s.substring(y,y+x);

String pal="";

for(int z=x-1;z>=0;z--)

pal=pal+s1.charAt(z);

if(pal.equals(s1))

System.out.println(s1);

}
import java.util.*;

class Q6

public static void main()

Scanner sc=new Scanner (System.in);

int count = 0;

System.out.println(“Enter no terms”);

int n =sc.nextInt();

int num=1;

System.out.println(“Numbers are”);

while (count < n) {

String power =Math.pow(2, num)+"";

if (power.contains("666")) {

System.out.println(num);

count++;

num++;

import java.util.Scanner;
class Q7 {

public static int sumOfSquares(int num) {

int sum = 0;

while (num > 0) {

sum += (num % 10) * (num % 10);

num /= 10;

return sum;

public static boolean isHappy(int num) {

while (num != 1 && num != 4) {

num = sumOfSquares(num);

return num == 1;

public static void main() {

Scanner sc = new Scanner(System.in);

System.out.print("Enter how many happy numbers to display: ");

int n = sc.nextInt();

int count = 0;

int num = 1;

while (count < n) {

if (isHappy(num)) {

System.out.println(num);
count++;

num++;

import java.util.*;

class Q8

public static void main()

Scanner sc=new Scanner(System.in);

System.out.println(“enter no terms”);

int n=sc.nextInt();

int c=0,od=0;int y=1;

System.out.println(“Numbers are”);

while(c<=n)

int x=y;

od=0;

while(x!=0)

int r=x%2;
if(r==1)

od++;

x=x/2;

if(od%2==1)

System.out.println(y);

c++;

y++;

import java.util.*;

class Q9

public static void main(String[] args)

Scanner sc = new Scanner(System.in);


int a[] = new int[10];

int b[] = new int[10];

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

System.out.println("Enter number in 1st array (a):");

a[x] = sc.nextInt();

System.out.println("Enter number in 2nd array (b):");

b[x] = sc.nextInt();

System.out.println("Numbers common to both arrays:");

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

for (int y = 0; y < b.length; y++)

if (a[x] == b[y])

System.out.print(a[x] + " ");

break;

System.out.println("Numbers in a but not in b:");

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

{
boolean found = false;

for (int y = 0; y < b.length; y++) {

if (a[x] == b[y])

found = true;

break;

if (!found)

System.out.print(a[x] + " ");

System.out.println();

System.out.println("Numbers in b but not in a:");

for (int x = 0; x < b.length; x++)

boolean found = false;

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

if (b[x] == a[y])

found = true;

break;

if (!found)
{

System.out.print(b[x] + " ");

System.out.println();

System.out.println("Union of both arrays:");

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

System.out.print(a[x] + " ");

for (int x = 0; x < b.length; x++)

boolean found = false;

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

if (b[x] == a[y])

found = true;

break;

if (!found) {

System.out.print(b[x] + " ");

}
}

import java.util.*;

import java.lang.*;

class Q10

public static void main()

Scanner sc=new Scanner (System.in);

int ar[]=new int[10];int le=0;

for(int x=0;x<10;x++)

System.out.println(“enter nos”);

ar[x]=sc.nextInt();

if(ar[x]%2==0)

le=Math.max(le,ar[x]);

If(le==0)

System.out.println(“no even no found”);

System.out.println(le);

You might also like