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

Class Ix

This Java program contains 5 code snippets that demonstrate different programming concepts: 1. A program that checks if a number is a "Duck number" by checking if it contains a 0. 2. A program that calculates the volume and surface area of a sphere given the radius. 3. A program that calculates the highest common factor (HCF) and lowest common multiple (LCM) of two numbers. 4. A program that converts an uppercase letter to lowercase and vice versa. 5. The code snippets demonstrate concepts like loops, conditionals, methods, and string manipulation.

Uploaded by

Dip Dey
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)
34 views6 pages

Class Ix

This Java program contains 5 code snippets that demonstrate different programming concepts: 1. A program that checks if a number is a "Duck number" by checking if it contains a 0. 2. A program that calculates the volume and surface area of a sphere given the radius. 3. A program that calculates the highest common factor (HCF) and lowest common multiple (LCM) of two numbers. 4. A program that converts an uppercase letter to lowercase and vice versa. 5. The code snippets demonstrate concepts like loops, conditionals, methods, and string manipulation.

Uploaded by

Dip Dey
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. i.

import java.util.*;
import java.io.*;
import java.util.Scanner;
public class DuckNumber {

public static boolean checkNumber(int number) {

while(number != 0) {

if(number%10 == 0)
return true;

number = number / 10;


}

return false;
}
// main() method start
public static void main(String args[])
{
int n1, n2;

Scanner sc=new Scanner(System.in);


System.out.println("Enter first number");

n1 = sc.nextInt();

System.out.println("Enter second number");

n2 = sc.nextInt();

if (checkNumber(n1))
System.out.println(n1 + " is a Duck number");
else
System.out.println(n1 + " is not a Duck number");
if (checkNumber(n2))
System.out.println(n2 + " is a Duck number");
else
System.out.println(n2 + " is not a Duck number");
}
}

2. Java program to calculate Volume and


// Surface area of Sphere
class volume {

static float pi = 3.14159f;

static float volume(float r)


{
float vol;
vol = ((float)4 / (float)3) * (pi * r * r * r);
return vol;
}

static float surface_area(float r) {


float sur_ar;
sur_ar = 4 * pi * r * r;
return sur_ar;
}

public static void main(String[] args)


{
float radius = 12;
float vol, sur_area;

vol = volume(radius);
sur_area = surface_area(radius);

System.out.println("Volume Of Sphere :" + vol);


System.out.println("Surface Area Of Sphere :" + sur_area);
}
}

4.
import java.util.Scanner;
public class JavaExample{
public static void main(String args[]){
int temp1, temp2, num1, num2, temp, hcf, lcm;
Scanner scanner = new Scanner(System.in);

System.out.print("Enter First Number: ");


num1 = scanner.nextInt();
System.out.print("Enter Second Number: ");
num2 = scanner.nextInt();
scanner.close();

temp1 = num1;
temp2 = num2;

while(temp2 != 0){
temp = temp2;
temp2 = temp1%temp2;
temp1 = temp;
}

hcf = temp1;
lcm = (num1*num2)/hcf;

System.out.println("HCF of input numbers: "+hcf);


System.out.println("LCM of input numbers: "+lcm);
}
}

5.
import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.print("Enter an uppercase letter: ");


String uppercaseLetter = scanner.nextLine();

System.out.print("Enter a lowercase letter: ");


String lowercaseLetter = scanner.nextLine();

System.out.println("The uppercase letter is: " + uppercaseLetter);


System.out.println("The lowercase letter is: " + lowercaseLetter);

char[] uppercaseLetters = uppercaseLetter.toCharArray();


char[] lowercaseLetters = lowercaseLetter.toCharArray();

for (int i = 0; i < uppercaseLetters.length; i++) {


uppercaseLetters[i] = Character.toLowerCase(uppercaseLetters[i]);
}

for (int i = 0; i < lowercaseLetters.length; i++) {


lowercaseLetters[i] = Character.toUpperCase(lowercaseLetters[i]);
}

String newUppercaseLetter = new String(uppercaseLetters);


String newLowercaseLetter = new String(lowercaseLetters);

System.out.println("The new uppercase letter is: " + newUppercaseLetter);


System.out.println("The new lowercase letter is: " + newLowercaseLetter);
}
}

You might also like