Java Lecture-2 27-July Operations
Java Lecture-2 27-July Operations
Practice Problems
import java.util.*;
class SumofDigits {
n = sc.nextInt();
m=n;
sumOfDigits += n%10;
OUTPUT -:
2. WAP to check whether a given number is palindrome
import java.util.*;
class Palindrome {
int n = sc.nextInt();
int r,sum=0,temp;
temp=n;
while(n>0){
r=n%10;
sum=(sum*10)+r;
n=n/10;
if(temp==sum)
else
System.out.println("not palindrome");
OUTPUT -:
3. Fibonacci series using a function
import java.util.*;
num1 = num2;
num2 = num3;
// Given Number N
int N = sc.nextInt();
Fibonacci(N);
}
4. WAP to generate all the prime numbers between 1 and n where n is a value
import java.util.*;
class gfg {
int x, y, flg;
System.out.println(
+ " are:");
if (x == 1 || x == 0)
continue;
flg = 1;
if (x % y == 0) {
flg = 0;
break;
if (flg == 1)
{
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
prime_N(N);
class BubbleSort {
int n = arr.length;
arr[j + 1] = temp;
}
void printArray(int arr[])
int n = arr.length;
System.out.println();
ob.bubbleSort(arr);
System.out.println("Sorted array");
ob.printArray(arr);