# Blog

QUICK ENQUIRY FORM

### WHAT WILL HAPPEN WHEN YOU SUBMIT THIS FORM

• After submitting the enquiry, you will be contacted by our team.
• Trainers(IT Professionals) may contact you if you need any clarification.
• Your contact information will be kept highly confidential & not be shared to 3rd Parties.
Quick Enquiry

## Find Even or Odd without using if and switch case

Hi Friends, Today, we are going to find Even or Odd Without using if and switch case.  The question asked here is – Write a program to find out if the given number is odd or even without using conditional statement like if or switch case. Solution : It is mentioned that We should not use if and switch case.  That is the clue we should remember here.  Hence, for finding out odd or even without those, we can go for array concept.  Let me try a simple Java program with a String array which consists of just two elements. Declare the two string values in the array with index o and 1. o => Even 1=> Odd Any number divide with two its give remainder as o or 1.  Thus, this remainder can be used in array index value. Program: public class EvenOdd { public static void main(String[] args) { String evenOdd[] = {“Even”,”Odd”};  // String array with only two elements int number = 3; int remainder= number % 2;  // remainder is calculated. System.out.println(evenOdd[remainder]); } } Output: Odd

## Learn Programming through Logical Thinking Series – 12

Hi Guys, In this post, our intention is to create Z Pattern (see below).  Already in our previous posts, we learnt X and Y Patterns.  Here our focus would be on creating the below pattern. package pattern.aug; public class ZPattern { public static void main(String[] args) { // TODO Auto-generated method stub //1st line for(int i=0;i<5;i++) { System.out.print(“*”); } System.out.println(); //2nd line for(int i=0;i<3;i++) { System.out.print(” “); } System.out.print(“*”); System.out.println(); //3rd line for(int i=0;i<2;i++) { System.out.print(” “); } System.out.print(“*”); System.out.println(); //4th line for(int i=0;i<1;i++) { System.out.print(” “); } System.out.print(“*”); System.out.println(); //5th line for(int i=0;i<5;i++) { System.out.print(“*”); } } } Output:

## Learn Programming through Logical Thinking Series – 11

Shall we try Y Pattern today through a Java Program?  The need is, we should bring Program: package pattern.aug; public class Ypattern { public static void main(String[] args) { // TODO Auto-generated method stub //1stline System.out.print(“*”); for(int i=0;i<5;i++) { System.out.print(” “); } System.out.print(“*”); System.out.println(); //2nd line System.out.print(” “); System.out.print(“*”); for(int i=0;i<3;i++) { System.out.print(” “); } System.out.print(“*”); System.out.println(); //3rd line for(int i=0;i<2;i++) { System.out.print(” “); } System.out.print(“*”); System.out.print(” “); System.out.print(“*”); System.out.println(); //remaining lines int n=0; while(n<3){ int row=0; while(row<3-n) { System.out.print(” “); row++; } System.out.print(“*”); System.out.println(); n++; } } } Output:

## Learn Programming through Logical Thinking Series – 10

Hi, In today’s post, we discuss about printing X pattern.  Already we know how to use looping statements in Java.  Here I am using while – nested while looping statements to derive X pattern.  The expected output is X Pattern Program public class XPattern { public static void main(String[] args) { int i=0,j; while(i<3){ j=0; while(j<(i*1)){ System.out.print(” “); j++; } int k=0; while(k<=(i-i)){ System.out.print(“*”); k++; } k=0; while(k<(4-(2*i))){ System.out.print(” “); k++; } k=0; while(k<=(i*0)){ System.out.print(“*”); k++; } System.out.println(); i++; } i=1; while(i>=0){ j=0; while(j<(i*1)){ System.out.print(” “); j++; } int k=0; while(k<=(i*0)){ System.out.print(“*”); k++; } k=4; while(k>(i*2)){ System.out.print(” “); k–; } j=0; while(j<=(i*0)){ System.out.print(“*”); j++; } System.out.println(); i–; } }} Output:

## Learn Programming through Logical Thinking Series – 9

In this series, probably this could be the toughest program I ever tried.  Already our colleague Srilatha Akka shared the logic for this program in the previous post  in C Language to solve this problem.  Well, First of all – What is the problem to be solved?  Let me share you that! The above pattern should be printed.  I am sharing my logic here with for deriving the above pattern here with. ABCD Pattern Program in Java public class AsciiTry { public static void main(String[] args) { int i=0,j,k,r,s,l,m; while(i<5){ j=0; while(j<(i*1)){ System.out.print(” “); j++; } k=0; while(k<=(i*0)){ r=65+i; System.out.printf(“%c”,r); k++; } l=0; while(l<7-(i*2)){ System.out.print(” “); l++; } m=0; while(m<=(i*0)){ s=73-i; if(s==69) break; System.out.printf(“%c”,s); m++; } l=7; while(l>7-((i*2)-1)){ System.out.print(” “); l–; } k=0; while(k<=(i*0)){ r=73+i; if(r==73){ break; } System.out.printf(“%c”,r); k++; } l=0; while(l<7-(i*2)){ System.out.print(” “); l++; } m=0; while(m<=(i*0)){ s=81-i; if(s==77) break; System.out.printf(“%c”,s); m++; } l=7; while(l>7-((i*2)-1)){ System.out.print(” “); l–; } k=0; while(k<=(i*0)){ r=81+i; if(r==81) break; System.out.printf(“%c”,r); k++; } l=0; while(l<7-(i*2)){ System.out.print(” “); l++; } m=0; while(m<=(i*0)){ s=89-i; if(s==85) break; System.out.printf(“%c”,s); m++; } l=7; while(l>7-((i*2)-1)){ System.out.print(” “); l–; } k=0; while(k<=(i*0)){ r=89+i; if(r==89) break; if(r==91) break; if(r==92) break; if(r==93) break; System.out.printf(“%c”,r); k++; } System.out.println(); i++; } } }

## Learn Programming through Logical Thinking Series – 8

This is one of the toughest questions, we discussed in our Programming class.  I spent almost 3 hours (or even more than that) to solve the below program.  My trainer asked to work on printing the below pattern program. I wrote in C language.  Please go through the program below.  As it is mainly dealing with looping statements, you can make use of the same logic in any programming language like Java, C#, etc. #include<stdio.h> #include<conio.h> void main() { int i,j,k,l,m,z=1,n,o,p,q,r,s,t,u,v,w; clrscr(); for(i=1;i<=5;i++) { for(j=1;j<i;j++) { printf(” “); } for(k=1;k<=z;k++) { printf(“%c”, i+64); } for(l=1;l<=9-(2*i);l++) { printf(” “); } for(m=1;m<=z;m++) { if(i==5){ break;} printf(“%c”, 74-i); } for(n=1;n<(2*i)-2;n++) { printf(” “); } for(o=1;o<=z;o++) { if(i==1){break;}; printf(“%c”,i+72); } for(p=1;p<=9-(2*i);p++) { printf(” “); } for(q=1;q<=z;q++) {  if(i==5){break;} printf(“%c”,82-i); } for(r=1;r<(2*i)-2;r++) { printf(” “); } for(s=1;s<=z;s++) { if(i==1){break;} printf(“%c”,i+80); } for(t=1;t<=9-(2*i);t++) { printf(” “); } for(u=1;u<=z;u++) { if(i==5){break;} printf(“%c”,90-i); } for(v=1;v<(2*i)-2;v++) { printf(” “); } for(w=1;w<=z;w++) { if(i==2){ printf(“%c”,i+88); }} printf(“\n”); } getch(); }

## Learn Programming through Logical Thinking Series – 7

Learn Programming through funny ways!  Here, we are going to solve Profit and Loss related Aptitude through our Logical Thinking series. QUESTION A, B, C subscribe Rs. 50,000 for a business. A subscribes Rs. 4000 more than B and B Rs. 5000 more than C. Out of a total profit of Rs. 35,000.  How much does A receive? ANSWER:  14700 ALGORITHM Get the total profit value from user Initialize a=4000,b=5000,amt=50000 Add the value of and b to get the a’s original amount Then add the a’s original amount and the b value and subtract it from amt and store it in cvalue Then divide the cvalue by 3 Find the a&b value by adding cvalue with a’s original amount and b value Find the ratio of a,b,c by dividing the a,b,c value by 1000 Now add the a,b,c ratios to get the total value Now find a’s share by multiplying profit value with a’s ratio and divide dy the total value Profit Share Program in Java package my.app2; import java.util.Scanner; public class App2 { public static void main(String[] args) { System.out.println(“enter the total profit”); Scanner scanner = new Scanner(System.in); int p = scanner.nextInt(); int a=4000,b=5000; int a_modval=a+b, a_share, cvalue_by_ab; int amt=50000, cValue,a_amount,b_amount,a_ratio,b_ratio,c_ratio,totalRatio; int sumOffab+a_modval; cValue_by_ab=amt-sumOfab; cValue=cValue_by_ab/3; a_amount=cValue+a_modval; b_amount=cValue+b; a_ratio=a_amount/1000; b_ratio=b_amount/1000; c_ratio=cValue/1000; totalRatio=a_ratio+b_ratio+c_ratio; // Calculating a’s share now.  a_share=(p*a_ratio)/totalRatio; System.out.print(“a’s share is: “+a_share); } }

## Learn Programming through Logical Thinking Series – 6

Today, we are going to learn about Pattern Programs here.  The given pattern to be printed is 4444 333 22 1   PATTERN PROGRAM package task.my.pro; public class PatternProgram{ public static void main(String[] args) { int no=4,round=0; do{ int column=0,row=0; while(column<4-round) { //Printing no value below System.out.print(no); column++; } no–; // Moving to next line System.out.println(” “); round++; do { System.out.print(” “); row++; }while(row<round); }while(round<4); } }   OUTPUT 4444 333 22 1