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);
System.out.println(ans);
public static boolean lastdigit(int a,int b){
return(a%10)==(b%10);
2.program to check if a given integer number is odd or even?
import java.util.*;
class Main {
public static void main(String[] args) {
System.out.println("Enter the integer");
Scanner scan=new Scanner(System.in);
int num=scan.nextInt();
if(num %2==0){
System.out.println("Number is even");
else{
System.out.println("Number is odd");
3.write a program to check if the program receive commend line argument or not?
import java.util.*;
class Main {
public static void main(String[] args) {
if(args.length==0){
System.out.println("No values”);
else{
for(int i=0;i<args.lenghth;i++){
System.out.println
4. charcter variable display in ascending order?
class main{
public static void main(String args[]){
char ch1='s';
char ch2='e';
if(ch1>=ch2){
System.out.println(ch2+","+ch1);
else{
System.out.println(ch1+","+ch2);
5.initialize 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'){
System.out.println(ch+" is an alphabet");
else if(ch>='0'&& ch<='9'){
System.out.println(ch+" is an digit");
}
else{
System.out.println(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=Character.toUpperCase(ch);
System.out.println(ch+" -> "+upper);
else{
char lower=Character.toLowerCase(ch);
System.out.println(ch+" -> "+lower);
8.Get color code from user and return the color name?
import java.util.*;
class main{
public static void main(String args[]){
Scanner scan =new Scanner(System.in);
System.out.println("give colour code");
String color=scan.nextLine().toUpperCase();
switch(color){
case "R":
System.out.println("color is red");
break;
case "B":
System.out.println("color is blue");
break;
case "G":
System.out.println("color is green");
break;
case "O":
System.out.println("color is orange");
break;
case "Y":
System.out.println("color is yellow");
break;
case "W":
System.out.println("color is white");
break;
default:
System.out.println("Invalid color");
10.write 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++){
System.out.print(i+" ");
11.program to print even number between 23 to 57.each 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){
System.out.println(i);
12.program 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)) {
System.out.println(i);
private static boolean isPrime(int num) {
if (num <= 1) {
return false;
for (int i = 2; i <= Math.sqrt(num); i++) {
if (num % i == 0) {
return false;
return true;
}
14.program to print the sum of all the digit of given number?
import java.util.Scanner;
public class DigitSum {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Prompt user for input
System.out.print("Enter a number: ");
int number = scanner.nextInt();
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
System.out.println("The sum of the digits is: " + sum);
scanner.close();