0% found this document useful (0 votes)
9 views2 pages

Java Interview Programs

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)
9 views2 pages

Java Interview Programs

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/ 2

50 Java Interview Programs with

Solutions
1. Hello World Program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

2. Swap two numbers without temp variable


public class SwapNumbers {
public static void main(String[] args) {
int a = 5, b = 10;
a = a + b;
b = a - b;
a = a - b;
System.out.println("a = " + a + ", b = " + b);
}
}

3. Check even or odd number


public class EvenOdd {
public static void main(String[] args) {
int num = 7;
if (num % 2 == 0)
System.out.println("Even");
else
System.out.println("Odd");
}
}

4. Find largest of 3 numbers


public class LargestOfThree {
public static void main(String[] args) {
int a = 10, b = 20, c = 15;
int largest = (a > b) ? (a > c ? a : c) : (b > c ? b : c);
System.out.println("Largest: " + largest);
}
}
5. Reverse a number
public class ReverseNumber {
public static void main(String[] args) {
int num = 1234, rev = 0;
while (num != 0) {
rev = rev * 10 + num % 10;
num /= 10;
}
System.out.println("Reversed: " + rev);
}
}

You might also like