Programming Shortcut

Write, Run and execute Your programs with simple and esay way by Programming Shortcut

Friday, February 15, 2019

Program to check a letter is vowel or consonant in java


Hello Friends! Welcome to programming shortcut
Today will discuss:
--> Program to find whether the alphabet is a vowel or consonant  in java or
--> java program to check vowel or consonant using a switch or
--> program to check an alphabet is a vowel or consonant in java or
--> Program to find whether the letter is a vowel or consonant  in java or
--> program to check a letter is a vowel or consonant in java


import java.util.Scanner;
public class Check_letter_to_vowel_or_consonant {
    public static void main(String[] args) {
       String ch;
       Scanner c = new Scanner(System.in);
       System.out.println("Enter letter to check vowel or consonant:");
       ch = c.next();
       switch(ch){
           case "a":
           case "e":
           case "i":
           case "o":
           case "u":
           case "A":
           case "E":
           case "I":
           case "O":
           case "U":
           System.out.println("The alphabet is a vowel");
           break;
           default:
           System.out.println("The alphabet is a consonant");
       }
    }
}



Output:

   First, run:
   Enter letter to check vowel or consonant:
   a
   The alphabet is a vowel

   Second-time run:
   Enter the alphabet :
   d
   The alphabet is a consonant

Explanation: In this programming, we use the Switch case to check an alphabet or a letter is a vowel or consonant


Hello, Friend We first write the program and compile them and run the program to check compiler error or run time error.
Please share the site and comment on your ideas and your suggestions. All suggestion was all welcome.
If any question or doubt in the programming please mention the comment.
Thank yours very much. 
More Code »

Monday, February 4, 2019

Decimal to binary in java with explanation

Hello Friends! Welcome to Programming Shortcut only programming,
Today we'll discuss how to convert a decimal to binary in java. there are two methods to convert decimal to binary:

1. Decimal to binary in java with array using while loop,

2. Decimal to binary in java without array using while loop.


Decimal to binary in java


import java.util.Scanner;
public class DecimaltoBinary  {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int a[] = new int[1000];
        System.out.println("Enter a Decimal number to convert binary");
        int decimalnum = in.nextInt();
        int temp = decimalnum; //the taken number to save take temp variable.
        int n = 0;
        while (temp > 0) { // checking the number to till '0'
            int rem = temp % 2; // taking remainder of number
            temp = temp / 2; // after taking remainder update the number
            a[n] = rem;  // store the remainder into a array
            n++;
        }

//print the array in reverse order
        System.out.print("The binary of " + decimalnum + " is: ");
        for (int i = n - 1; i >= 0; i--) {
            System.out.print(a[i]);
        }
        System.out.println("\n");
    }
}

Output:
Enter a Decimal number to convert binary
23
The binary of 23 is: 10111


Decimal to binary in java without array


import java.util.Scanner;
public class DecimaltoBinary  {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println("Enter a Decimal number to convert binary");
        int num = input.nextInt();
        int n = num;
        String temp = "";
        while (n > 0) {
            int rem = n % 2;
            n = n / 2;
            temp = temp + rem;
        }
        String bin = new StringBuffer(temp).reverse().toString();

        System.out.println("The binary number of " + num + " is: " + bin);
    }
}

Output:
Enter a Decimal number to convert binary
24
The binary number of 24 is: 11000

Note: if adding in the String value store in the last of string value

 For example:
 String frist= "Programming";
 String last="Shortcut";
 String name= frist+last;
 System.out.println(name);

 output: ProgrammingShotcut

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this java programming code or input & output please comment below
If you have another question about java programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

program to check a alphabet is vowel or consonant in c++

Hello Friends! Welcome to programming shortcut
Today will discuss:
--> Program to find whether the alphabet is a vowel or consonant  in c++ or
--> c++ program to check vowel or consonant using a switch or
--> program to check an alphabet is a vowel or consonant in c++


#include <iostream>
using namespace std;
int main(){
 char ch;
 cout<<"Enter an alphabet :"<<endl;
 cin>>ch;
 switch(ch)
 {
  case 'a':
  case 'e':
  case 'i':
  case 'o':
  case 'u':
  case 'A':
  case 'E':
  case 'I':
  case 'O':
  case 'U':
   cout<<"Alphabet is a vowel"<<endl;
   break;
  default:
   cout<<"Alphabet is a consonant";
 }
 return 0;
}



Output:

   First, run:
   Enter the alphabet :
   a
   The alphabet is a vowel

   Second-time run:
   Enter the alphabet :
   d
   The alphabet is a consonant

Explanation: In this programming, we use the Switch case to check an alphabet is a vowel or consonant


Hello, Friend We first write the program and compile them and run the program to check compiler error or run time error.
Please share the site and comment on your ideas and your suggestions. All suggestion was all welcome.
If any question or doubt in the programming please mention the comment.
Thank yours very much. 
More Code »

Program to find whether the alphabet is a vowel or consonant

Hello Friends! Welcome to programming shortcut
Today will discuss:
--> Program to find whether the alphabet is a vowel or consonant or
--> c program to check vowel or consonant using a switch or
--> program to check an alphabet is a vowel or consonant


#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
printf("Enter an alphabet : \n");
scanf("%c",&ch);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
 case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("Alphabet is a vowel\n");
break;
default:
printf("Alphabet is a consonant\n");
}
getch();
}


Output:

   First, run:
   Enter the alphabet :
   a
   Alphabet is a vowel

   Second Time run:
   Enter the alphabet :
   d
   Alphabet is a consonant

Explanation: In this programming, we use the Switch case to check an alphabet is a vowel or consonant


Hello, Friend We first write the program and compile them and run the program to check compiler error or run time error.
Please share the site and comment on your ideas and your suggestions. All suggestion was all welcome.
If any question or doubt in the programming please mention the comment.
Thank yours very much. 
More Code »

Short name by java program

Hello Friends, Welcome to my blog

Today will write a program to the short name by java program, this problem is also asking in many ways they are following:
 1. Java Program to Convert a Person Name in Abbreviated.
 2. wap to print the short name of the user.
 3. Java program to convert full name to short name.
 4. Java program to a short name.
 5. Abbreviation of Java programming language.

 Problem:-
    Enter Name: Anant Deep Vishwakarma
        Output: A. D. Vishwakarma

 Solutions:-
    1. Store Name in a name String.
    2. Split Name String and Store to a temp string array.
    3. Find temp string array length store value in other variables.
    4. Take a loop to store all value to expect the last name and print the first character by value with
       dot or abbreviation.
    5. then print the last value of temp string all Character

 Explain:
    For example a store name 'Anant Deep Vishwakarma'in a name string and then split value into temp string array as temp[0]='Anant', temp[1]='Deep' and temp[2]='Vishwakarma', after that count length of temp string array and use loop to left the last index value last name 'Vishwakarma', in loop print first char of every index value within loop. in the last print last index of program

Best java program example:

    import java.util.*;
    class SName
    {
     public static void main(String[] args)
        {
            String n;
            Scanner c=new Scanner(System.in);
            System.out.print("Enter the user name:");
            n=c.nextLine();
            String [] t=n.split(" ");
            int l=t.length;
            System.out.print("Your Short name:");
            for(int i=0;i<l-1;i++)
            {
                System.out.print(t[i].charAt(0)+".");
            }
            System.out.print(t[l-1]);
         }
    }
     
I hope you understand the program is any query please comment below your query I reply your questions soon.
Bye..
       
More Code »

Java program to perform sum of digits until single digit is obtained

 Hello Friends!
 Today will discuss do while loop with an example, how to make a program in java by do-while loop, do while loop in java program an example with explanation.
 Write a program in java to find the sum of digits of a number until the sum is reduced to 1 digit.
 For example:
  The number is 538769.
  Then 5+3+8+7+6+9=38
  3+8=11
   11=2

Finding sum of digits of a number until sum becomes single digit java program


import java.util.Scanner;
public class do_while {
   public static void main(String[] args){
    long num,dig,sum;
    Scanner in =new Scanner(System.in);
System.out.print("Enter a number :");
    num=in.nextLong();
    System.out.println("");
System.out.print(num);
do{
        sum = 0;
        while(num!=0)
{
dig=num%10;
            sum+=dig;
            num/=10;
}
        System.out.print("->"+sum);
        num=sum;
}while(num/10!=0);
   }
}
Output: Enter a number : 538769
        538769->38->11->2

Explanation :

    do{
/* 1: program code */
}while(num/10!=0);
        The Above Condition is not exited while a number is more than one digit.
     
/* 1: program code */
while(num!=0)
{
dig=num%10;
sum+=dig;
num/=10;
}
     Here we use program code to find a sum of digit then the given program exapmle is for "Sum of digits of a number until the sum is reduced to 1 digit"

So we find Your Program

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this java programming code or input & output please comment below
If you have another question about java programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

Sum of digits of a number until the sum is reduced to 1 digit in c++

 Hello Friends! Welcome to Programming Shortcut
Today will discuss do while loop with an example, how to make a program in c++ by the do-while loop, do while loop in c++ with an example with explanation.
 Write a program in c++ to find the sum of digits of a number until the sum is reduced to 1 digit.
 For example
  The number is 538769.
  Then 5+3+8+7+6+9=38
            3+8=11
            11=2

Sum of digits of a number until the sum is reduced to 1 digit in c++ program

#include <iostream>
using namespace std;
int main()
{
long num,dig,sum;
cout<<"Enter a number :"<<endl;
cin>>num;
cout<<num<<endl;
do{
sum = 0;
while(num!=0)
{
dig=num%10;
sum+=dig;
num/=10;
}
cout<<"->"<<sum<<endl;
num=sum;
}while(num/10!=0);  /*while num is more than one digit*/
return 0;
}

Output: Enter The number 538769
            538769->38->11->2

Explanation :

      do{
/* 1: program code */
}while(num/10!=0);

                The Above Condition is not exit while num. is more than one digit.
     
/* 1: program code */
while(num!=0) 
{
dig=num%10;
sum+=dig;
num/=10;
}

     Here we use program code to find a sum of digit then the given program example is for "Sum of digits of a number until the sum is reduced to 1 digit"

So we find Your Program what we want. 

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this c programming code or input & output please comment below
If you have another question about c programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

Sum of digits of a number until the sum is reduced to 1 digit in c

 Hello Friends!
 Today will discuss do while loop with the example, how to make a program in c by a do-while loop,   do while loop in c programming example with explanation and how to make c program to Sum of digits of a number until the sum is reduced to 1 digit. Nested Loop in c program
 Write a program in c to find the sum of digits of a number until the sum is reduced to 1 digit.
 For example: 
 The number is 538769.
 Then 5+3+8+7+6+9=38
          3+8=11
          11=2

Sum of digits of a number until the sum is reduced to 1 digit in c program

#include<stdio.h>
int main(void)
{
long num,dig,sum;
printf("Enter a number : ");
scanf("%ld",&num);
printf("\n%ld",num);
do{
sum = 0;
while(num!=0)
{
dig=num%10;
sum+=dig;
num/=10;
}
printf("->%d",sum);
num=sum;
}while(num/10!=0);  /*while num is more than one digit*/
return 0;
}

Output: Enter The number 538769
              538769->38->11->2


Explanation :

      do{
/* 1: program code */
}while(num/10!=0);
The Above Condition is not exit while num. is more than one digit.
      
 /* 1: program code */
while(num!=0) 
{
dig=num%10;
sum+=dig;
num/=10;
}
Here we use program code to find a sum of digit then the given program example is for "Sum of digits of a number until the sum is reduced to 1 digit"

So we find Your Program what we want. 

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this c programming code or input & output please comment below
If you have another question about c programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

Java program to reverse a number


Hello friends! welcome to my blog
Today will discuss the basic concept and simplest way to how to reverse a number in java by programming and how to make program for reverse of a number without array in java programming. How to how to count number of digit in a number in java programming, write a program to count number of digit in java

Write a program to reverse a number


import java.util.Scanner;
public class reverse{
public static void main(String[] args){
int n, r=0,d;
    Scanner in =new Scanner(System.in);
    System.out.println("Enter the number");
n=in.nextInt();
System.out.println("Number befour reverse= " +n);
while(n>0){
d= n%10;
r= r*10+d;
n=n/10;
}
System.out.println("Number After reverse= "+r);
}
}


Output: Enter the Number
        1234
Number befour reverse= 1234
Number After reverse= 4321

Write a program to count no of digit of a number


import java.util.Scanner;
public class count{
public static void main(String[] args){
int n, c=0,d;
    Scanner in=new Scanner(System.in);
    System.out.println("Enter the number");
n=in.nextInt();
while(n>0){
d= n%10;
n=n/10;
c++;
}
System.out.println("The entered number has "+ d +"digit");
}
}


Output: Enter the Number
            1234
   The entered number has 4 digit

 

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this java programming code or input & output please comment below
If you have another question about java programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

How to reverse a number in c++ program

Hello friends! welcome to my blog
Today will discuss the basic concept and simplest way to how to reverse a number in c++ by programming and how to make program for reverse of a number without array in c++ programming. How to how to count number of digit in a number in c++ programming.

write a program to reverse a number



#include <iostream>
using namespace std;
int main()
{
    int n, r=0,d;
    cout<<"Enter the number"<<endl;
cin>>n;
cout<<"Number befour reverse= "<<n <<endl;
while(n>0){
d= n%10;
r= r*10+d;
n=n/10;
}
cout<<"Number After reverse= "<<r<<endl;
return 0;
}


Output: Enter the Number
             1234
     Number befour reverse= 1234
     Number After reverse= 4321

program to count no of digit of a number

#include <iostream>
using namespace std;
int main()
{
int n, c=0,d;
    clrscr();
    cout<<"Enter the number"<<endl;
cin>>n;
while(n>0){
d= n%10;
n=n/10;
c++;
}
cout<<"The enter number have"<<d <<"digit";
return 0;
}


Output:Enter the Number
            1234
    The enter number have 4 digit
 


I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this c++ programming code or input & output please comment below
If you have another question about c++ programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

reverse a number in c program

Hello friends! welcome to my blog
Today will discuss the basic concept and simplest way to how to reverse a number in c by programming and how to make program for reverse of a number without array in c programming,

Write a program to reverse a number


#include<stdio.h>
int main(void)
{
int n, r=0,d;
    clrscr();
    printf("Enter the number\n");
scanf("%d",&n);
printf("Number befour reverse= %d ",n);
while(n>0){
d= n%10;
r= r*10+d;
n=n/10;
}
printf("Number After reverse= %d", r);
return 0;
}


Output: Enter the Number
        1234
Number befour reverse= 1234
Number After reverse= 4321

Program to count no of digit to a number


#include<stdio.h>
int main(void)
{
int n, c=0,d;
    clrscr();
    printf("Enter the number\n");
scanf("%d",&n);
while(n>0){
d= n%10;
n=n/10;
c++;
}
printf("The entered number has %d digits", c);
return 0;
}


Output: Enter the Number
       1234
   The entered number has 4 digits

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this c programming code or input & output please comment below
If you have another question about c programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

Programming Shortcut only programming

Programming Shortcut is collections in java best programs with example, best c programs with example and best c++ programs with example, best way to learn java, c and c++

About Programming Shortcut

This is a programming learning website that can help you learn and when your write your programming code. And all programming code is compiled run programming code in the following programming language C, c++, Java, php and Javascript Languages. find your programming read, understand the programming then copy and past and run your program and save your golden time to typing the program becuse you learn more in leas time. All Programming is codeing is ease to understand the programming