0% found this document useful (0 votes)
19 views6 pages

1st Week

Uploaded by

borugaddaaditya5
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)
19 views6 pages

1st Week

Uploaded by

borugaddaaditya5
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/ 6

1) Sum of Last Digits of Two Given Numbers

import java.util.Scanner;

public class SumLastDigits {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int a = sc.nextInt();

int b = sc.nextInt();

int sum = (a % 10) + (b % 10);

System.out.println("Sum of last digits: " + sum);

2) Is N an Exact Multiple of M?

import java.util.Scanner;

public class MultipleCheck {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int N = sc.nextInt();

int M = sc.nextInt();

if (M != 0 && N % M == 0) {

System.out.println("Yes");

} else {

System.out.println("No");

}
3. Combine Strings

import java.util.Scanner;

public class MultipleCheck {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int N = sc.nextInt();

int M = sc.nextInt();

if (M != 0 && N % M == 0) {

System.out.println("Yes");

} else {

System.out.println("No");

4. Even or Odd

import java.util.Scanner;

public class EvenOdd {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int num = sc.nextInt();

if (num % 2 == 0) {

System.out.println("Even");

} else {

System.out.println("Odd");

}
5. Second Last Digit of a Given Number

import java.util.Scanner;

public class SecondLastDigit {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int num = Math.abs(sc.nextInt());

if (num < 10) {

System.out.println("No second last digit");

} else {

int secondLast = (num / 10) % 10;

System.out.println("Second last digit: " + secondLast);

6. Alternate String Combiner

import java.util.Scanner;

public class AlternateStringCombiner {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String s1 = sc.nextLine();

String s2 = sc.nextLine();

StringBuilder result = new StringBuilder();

int maxLength = Math.max(s1.length(), s2.length());

for (int i = 0; i < maxLength; i++) {

if (i < s1.length()) result.append(s1.charAt(i));


if (i < s2.length()) result.append(s2.charAt(i));

System.out.println("Combined: " + result.toString());

7. Padovan Sequence

import java.util.Scanner;

public class PadovanSequence {

public static int padovan(int n) {

if (n == 0 || n == 1 || n == 2)

return 1;

return padovan(n - 2) + padovan(n - 3);

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt(); // Number of terms

for (int i = 0; i < n; i++) {

System.out.print(padovan(i) + " ");

8.Leaders in an Array

import java.util.Scanner;

public class LeadersInArray {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);


int n = sc.nextInt(); // Number of elements

int[] arr = new int[n];

for(int i=0; i<n; i++) {

arr[i] = sc.nextInt();

for (int i = 0; i < n; i++) {

boolean isLeader = true;

for (int j = i + 1; j < n; j++) {

if (arr[i] <= arr[j]) {

isLeader = false;

break;

if (isLeader) {

System.out.print(arr[i] + " ");

8. Find the Value of a Number Raised (Power Calculation)

import java.util.Scanner;

public class PowerCalculation {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

double base = sc.nextDouble();


int exponent = sc.nextInt();

double result = Math.pow(base, exponent);

System.out.println("Result: " + result);

You might also like