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

Java Programs for Basic Operations

The document contains a series of Java programs that demonstrate various programming concepts, such as checking for the same last digit, determining if a number is odd or even, handling command line arguments, sorting characters, identifying character types, converting case, retrieving color names from codes, printing numbers in a specific format, and calculating the sum of digits. Each program is structured with a main method and relevant logic to achieve its specific task. The examples illustrate basic control structures, input handling, and mathematical operations in Java.

Uploaded by

gnanam7010125187
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)
6 views6 pages

Java Programs for Basic Operations

The document contains a series of Java programs that demonstrate various programming concepts, such as checking for the same last digit, determining if a number is odd or even, handling command line arguments, sorting characters, identifying character types, converting case, retrieving color names from codes, printing numbers in a specific format, and calculating the sum of digits. Each program is structured with a main method and relevant logic to achieve its specific task. The examples illustrate basic control structures, input handling, and mathematical operations in Java.

Uploaded by

gnanam7010125187
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

1-B.

given two non-negative int values,print true,if they have the same last digit,such as with
27and 57?

class Main {

public static void main(String[] args) {

boolean ans=lastdigit(27,57);

[Link](ans);

public static boolean lastdigit(int a,int b){

return(a%10)==(b%10);

[Link] to check if a given integer number is odd or even?

import [Link].*;

class Main {

public static void main(String[] args) {

[Link]("Enter the integer");

Scanner scan=new Scanner([Link]);

int num=[Link]();

if(num %2==0){

[Link]("Number is even");

else{

[Link]("Number is odd");

[Link] a program to check if the program receive commend line argument or not?

import [Link].*;

class Main {

public static void main(String[] args) {


if([Link]==0){

[Link]("No values”);

else{

for(int i=0;i<[Link];i++){

[Link]

4. charcter variable display in ascending order?

class main{

public static void main(String args[]){

char ch1='s';

char ch2='e';

if(ch1>=ch2){

[Link](ch2+","+ch1);

else{

[Link](ch1+","+ch2);

[Link] a character variable in a program and print alphabet or digit or special char?

class main{

public static void main(String args[]){

char ch='&';

if(ch>='a'&& ch<='z'||ch>='A'&& ch<='Z'){

[Link](ch+" is an alphabet");

else if(ch>='0'&& ch<='9'){

[Link](ch+" is an digit");
}

else{

[Link](ch+ " is an special charcter");

7. Uppercase to lowercase &lowercase to uppercase?

class Main {

public static void main(String[] args) {

char ch='a';

if(ch >= 'a'&& ch <= 'z'){

char upper=[Link](ch);

[Link](ch+" -> "+upper);

else{

char lower=[Link](ch);

[Link](ch+" -> "+lower);

[Link] color code from user and return the color name?

import [Link].*;

class main{

public static void main(String args[]){

Scanner scan =new Scanner([Link]);

[Link]("give colour code");

String color=[Link]().toUpperCase();

switch(color){

case "R":

[Link]("color is red");

break;
case "B":

[Link]("color is blue");

break;

case "G":

[Link]("color is green");

break;

case "O":

[Link]("color is orange");

break;

case "Y":

[Link]("color is yellow");

break;

case "W":

[Link]("color is white");

break;

default:

[Link]("Invalid color");

[Link] a program to print number from 1 to 10 single row one tab space?

class Main {

public static void main(String[] args) {

for(int i=1;i<=10;i++){

[Link](i+" ");

[Link] to print even number between 23 to [Link] number should be println in asepared
row?
class Main {

public static void main(String[] args) {

for(int i=23;i<=57;i++){

if(i%2==0){

[Link](i);

[Link] to print prime number between 10 and 99?

class Main {

public static void main(String[] args) {

for (int i = 10; i <= 99; i++) {

if (isPrime(i)) {

[Link](i);

private static boolean isPrime(int num) {

if (num <= 1) {

return false;

for (int i = 2; i <= [Link](num); i++) {

if (num % i == 0) {

return false;

return true;

}
[Link] to print the sum of all the digit of given number?

import [Link];

public class DigitSum {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

// Prompt user for input

[Link]("Enter a number: ");

int number = [Link]();

int sum = 0;

// Calculate the sum of digits

while (number != 0) {

sum += number % 10; // Extract the last digit and add to sum

number /= 10; // Remove the last digit

// Print the result

[Link]("The sum of the digits is: " + sum);

[Link]();

You might also like