Skip to main content

Posts

Showing posts with the label Flow Control Statement

Write a Java program to find if the given number is palindrome or not Example1) C:\>java Sample 110011 O/P: 110011 is a palindrome Example2) C:\>java Sample 1234 O/P: 1234 is not a palindrome

Write a Java program to find if the given number is palindrome or not Example1) C:\>java Sample 110011 O/P: 110011 is a palindrome Example2) C:\>java Sample 1234 O/P: 1234 is not a palindrome //Use One Dimensional Array.  >> If you have any alternate methods then please comment below. public class Sample { public static void main(String[] args) { int n=Integer.parseInt(args[0]); int a=n; int c=0,rem; while(a!=0) { rem=a%10; c=c*10+rem;      a=a/10;     } if(n==c)         System.out.println(n+" is a palindrome"); else         System.out.println(n+" is not a palindrome");            } } Write a program to print the sum of the elements of an array following the given below condition. If the array has 6 and 7 in succeeding orders, ignore the numbers between 6 and 7 and consider the other numbers for calculation of sum. Eg1) Array Elements - 10,3,6,1,2,7,9 O/P: 22    [i.e 10+3+9] Eg2) Array Elements - 7,1,2,3,6 O/P:19

Write a program to reverse a given number and print Example1) I/P: 1234 O/P:4321 Example2) I/P:1004 O/P:4001

Write a program to reverse a given number and print Example1) I/P: 1234 O/P:4321 Example2) I/P:1004 O/P:4001 import java.util.Scanner; public class ReverseNumber { public static void main(String[] args)  { int n,rem; Scanner s=new Scanner(System.in); System.out.println("I/P:"); n=s.nextInt(); while(n!=0) { rem=n%10;   System.out.println(rem);   n=n/10;     }     } } Write a program to print the sum of the elements of an array following the given below condition. If the array has 6 and 7 in succeeding orders, ignore the numbers between 6 and 7 and consider the other numbers for calculation of sum. Eg1) Array Elements - 10,3,6,1,2,7,9 O/P: 22    [i.e 10+3+9] Eg2) Array Elements - 7,1,2,3,6 O/P:19 Eg3) Array Elements - 1,6,4,7,9 O/P:10 //Use One Dimensional Array.  >> If you have any alternate methods then please comment below. import java.io.*; public class ConditionalSum { static void conditionalSum(int l[], int a, int b) { int sum = 0

Write a program to print * in Floyds format (using for and while loop) * * * * * * Example1) C:\>java Sample O/P: Please enter an integer number Example2) C:\>java Sample 3 O/P : * * * * * *

Write a program to print * in Floyds format (using for and while loop) * *  * *  *   * Example1) C:\>java Sample  O/P: Please enter an integer number Example2) C:\>java Sample 3 O/P : * *  *  *  *  * public class FloydsFormat { public static void main(String[] args)  { int n=Integer.parseInt(args[0]); if(args.length==0){ System.out.println("Please Enter an Integer number"); } else { for(int a=1;a<=n;a++){   for(int b=1;b<=a;b++){   System.out.print("* ");   }             System.out.println(); } } } } Write a program to print the sum of the elements of an array following the given below condition. If the array has 6 and 7 in succeeding orders, ignore the numbers between 6 and 7 and consider the other numbers for calculation of sum. Eg1) Array Elements - 10,3,6,1,2,7,9 O/P: 22    [i.e 10+3+9] Eg2) Array Elements - 7,1,2,3,6 O/P:19 Eg3) Array Elements - 1,6,4,7,9 O/P:10 //Use One Dimensional Array.  >> If you have

Write a program to print the sum of all the digits of a given number. Example1) I/P:1234 O/P:10

 Write a program to print the sum of all the digits of a given number. Example1)  I/P:1234 O/P:10 import java.util.Scanner; public class SumofDigits { public static void main(String[] args)  { int n,rem,sum; Scanner s=new Scanner(System.in); System.out.println("Enter the number:"); n=s.nextInt(); for(sum=0;n!=0;n/=10) { rem=n%10; sum=sum+rem; }   System.out.println(sum); } }

Write a program to print prime numbers between 10 and 99.

Write a program to print prime numbers between 10 and 99. import java.util.Scanner; public class SumofDigits { public static void main(String[] args)  { int n,rem,sum; Scanner s=new Scanner(System.in); System.out.println("Enter the number:"); n=s.nextInt(); for(sum=0;n!=0;n/=10) { rem=n%10; sum=sum+rem; }   System.out.println(sum); } } Write a program to print the sum of the elements of an array following the given below condition. If the array has 6 and 7 in succeeding orders, ignore the numbers between 6 and 7 and consider the other numbers for calculation of sum. Eg1) Array Elements - 10,3,6,1,2,7,9 O/P: 22    [i.e 10+3+9] Eg2) Array Elements - 7,1,2,3,6 O/P:19 Eg3) Array Elements - 1,6,4,7,9 O/P:10 //Use One Dimensional Array.  >> If you have any alternate methods then please comment below. import java.io.*; public class ConditionalSum { static void conditionalSum(int l[], int a, int b) { int sum = 0; boolean add = true;

Write a program to print even numbers between 23 and 57. Each number should be printed in a separate row.

Write a program to print even numbers between 23 and 57. Each number should be printed in a separate row. public class PrimeNumbersBetween { public static void main(String[] args) {           int check,i;           for(i=0;i<=99;i++) {           check=0;           for(int j=2;j<i;j++) {           if(i%j==0) {           check=1;           break;           }           }           if(check==0)           System.out.println(i);           } } } Write a program to accept gender ("Male" or "Female") and age from command line arguments and print the percentage of interest based on the given conditions. If the gender is 'Female' and age is between 1 and 58, the percentage of interest is 8.2%. If the gender is 'Female' and age is between 59 and 100, the percentage of interest is 9.2%. If the gender is 'Male' and age is between 1 and 58, the percentage of interest is 8.4%. If the gender is 'Male' and age is betw