Posts

Showing posts with the label Javacode

Start Java Programming free online form basic with Certificate

Image
  Start Java Programming free online  form basic with certificate The course will cover all aspect of Java programming language in great clarity and granularity. You will begin with the basics, starting with the installation of the required software. You will learn topics like "What is Java?", Variables, Operators, etc. to get a very good understanding of the fundamentals of Java. Start  Java course with Great Learning Academy The course will also cover most used and handy software practices that are used in the industry such as Object-Oriented Programming Systems, Inheritance and Collections in Java. Register now free of cost and start your course and get certificate after completion   Click here to start learning Course Syllabus Java Programming Agenda What is Java? Install Java & Java IDE First Java Program Variables and Data Types in Java Operators in Java Flow Control Statements in Java Functions in Java Arrays in Java Object Oriented Programming in Java Inh...

Mindtree|Remove all vowel from user input a string in java

Image
 Remove all vowel from user input a string in java In this java program, we have to delete all occurrences of vowel characters from a given string and then print it on screen The logic behind this question is simple. It is to remove the vowels in the given string and display the input string without vowels (i.e with only consonants).  Here we are using two approach. 1.Using Indexof()  Method Java String indexOf() method is used to find the index of a specified character  or substring in a given String.  Method returns -1 if the specified char/substring is not found in the particular String. import java.util.Scanner; public class R_Vowels { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.err.println("Enter the String :");         String s1=sc.nextLine();         String s2="AEIOUaeiou";         String s3=" ";      for(int i=0;i<s1.length...

Java Program for shop Bill to Calculate total amount of product with discount

Image
 Java Program for shop Bill to print total amount with discount To print total amount with discount import java.util.Scanner; class Shop { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter the product name and its price."); String a=sc.next(); double r1=sc.nextDouble(); System.out.println("Enter the 2nd product name and its price."); String b=sc.next(); double r2=sc.nextDouble(); System.out.println("Enter the 3rd product name and its price."); String c=sc.next(); double r3=sc.nextDouble(); double d1=r1-(r1*0.08); double d2=r2-(r2*0.08); double d3=r3-(r3*0.08); System.out.println("Product  Price  DiscountPrice"); System.out.println("-----------------------------"); System.out.println("  "+a+"  "+r1+"  "+d1); System.out.println("  "+b+"  "+r2+"  "+d2); System.out.println("  "+c+"  "+r3+"  "+d3); Sys...

Java Program to Print the number is either positive negative or zero.

 Java Program to Print the number is either positive negative or zero. In this java program, we will read integer number and check whether it is positive, negative or zero. Using If-else statement with Method  import java.util.Scanner; class Number { String pnz(int a) { if(a<0) return "Negative"; else if(a>0) return "Positive"; return "Zero"; } public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter a number."); int x=sc.nextInt(); Number n=new Number(); System.out.println(n.pnz(x)); } }

Java program to Reverse a number using do while loop

Image
Java program to Reverse a number using do while loop  Reverse number or digit using do while loop Example: num = 456 rev_num = 0 rev_num = rev_num *10 + reminder = 6 num = num/10 = 45 rev_num = rev_num *10 + reminder = 60 + 5 = 65 num = num/10 = 4 rev_num = rev_num *10 + reminder = 650 + 4 = 654 num = num/10 = 0 Reverse number or digit using do while loop  class RevNum { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter the number:"); int num=sc.nextInt(); int rev=0; do{ int reminder=num%10; rev=rev*10+reminder; num=num/10; }while(num!=0); System.out.println("Reversed Numer is: "+rev); } }

Java program To check given number is special two digit number or not

Image
Java program To check given number is special two digit number or not This program helps to check whether it is special two Digit number or not. Special Two Digit Number are number for which sum of it’s  sum of it’s digits and product of it’s digits is equal to the original number. Example: Original Number : 29 Step 1 : Sum of two digit is  2+9 = 11 Step 2 : Product of two digit 2*9 = 18 Sum of sum of two digit and product of two digit as calculate in above steps and that will be 11+18 = 29 Calculated Number is equal to original number so we can say it is Special Two Digit Number.   Java Program for   special two digit number or not import java.util.Scanner; class SpecialTwoDigit { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter a two digit number to check if it is special or not."); int original_No=sc.nextInt(); int d1=x/10; int d2=x%10; int sum_product=d1+d2+d1*d2; if(sum_product==original_No) System.out.pr...

Java program for nested if-else else if statement

Image
Java program for nested if-else else if statement A programming language uses control statements to control the flow of execution of program based on certain conditions. you can use one if or else if statement inside another if or else if statement. Nested else-if Program if statements are executed from the top towards the bottom. As soon as the test expression is true, codes inside the body of that the if statement is executed. Then, the control of the program jumps outside the if-else-if ladder. If none of the conditions is true, then the final else statement will be executed. The final else acts as a default condition; that is, if all other conditional tests fail, then the last else statement is performed. A  program construct that is based upon a sequence of nested with if-else-if ladder import java.util.Scanner; class Story { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter the Number:"); int a=sc.nextInt(); if(a%3==0...

Java program to find student total mark Average & Percentage of mark using Method

Image
Java program to find student total mark Average  & Percentage of mark using Method This Java program allows users to enter five different values for five subjects. And then, this Java program finds the Total, Average, and Percentage of those Five Subjects. Using Method import java.util.Scanner; class Student {       int Total(int w,int x,int y,int z,int a){       return w+x+y+z; }        double Avg(int a,int b,int c,int d,int e){         return (a+b+c+d)/4.0; }        double per(int a1,int b1,int c1,int d1,int e1) {        return (a+b+c+d/4)*100 } public static void main(String args[]){ Student e=new Student(); Scanner sc=new Scanner(System.in); System.out.println("Enter the name with his four subject marks."); String name=sc.nextLine(); int p=sc.nextInt(); int q=sc.nextInt(); int r=sc.nextInt(); int s=sc.nextInt(); int t=sc.nextInt(); System.out.println(...

Java program to print sum of the given number

Image
 Java program to print sum of the given number Java program  to print sum of the given number by using Do While loop Example 1 import java.util.Scanner; class SumofDigits { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter the number:"); int n=sc.nextInt(); int sum=0; do{ int a=n%10; sum=sum+a; n=n/10; }while(n!=0); System.out.println("Sum of Digits is: "+sum); } } Example 2 To calculate the sum of the digits of any given number with the help of Java Programs by using  Static Method class SumOfDigits { public static void main(String arg[]) {     long n,s;                   Scanner sc=new Scanner(System.in);     System.out.println("Enter a number ");                    n=sc.nextLong();     s=sum(n);     System.out.println("Sum of digits...

Java Program to print sum of even and odd digit of given number

Image
Java Program to print sum of even and odd digit of given number sum of even and odd digit of given number When any integer value which ends in 0,2,4,6,8 is divided by two it is called as an even number Example for even numbers – 34,-64,78,788 When any integer value which ends in 0,1,3,5,7,9 is not divided by two it is called as an odd number Example for odd numbers – 33,-69,75,785   We can use a modular operator to find odd or even number in the given range. if n%2==0,  n is an even number if n%2==1,  n is an odd number   This program allows the user to enter a maximum number of digits and then, the program will find out even and odd digit of given number and  sum up odd and even numbers entered number using a  Do While loop       import java.util.Scanner; class SumofEODigits { public static void main(String args[])        { Scanner sc=new Scanner(System.in); System.out.println("Enter the number:"); int n=...

Java program to print sum square of n Natural number

Image
 Java code print sum of square of  n Natural number The sum of squares of the first n natural numbers is found by adding up all the squares. Using Loops − the code loops through the digits until n and   find their square, then add this to a sum variable that outputs the sum. sum of n natural number  import java.util.Scanner;  public class SumOfSquares  {  public static void main(String[] args)  {       Scanner sc = new Scanner(System.in);       System.out.print("Enter Integer: ");       int n = sc.nextInt();       System.out.println("User entered digit: " + n);       int sum = 0;       for (int x=1;x<=n;x++) {         sum = sum + (x*x);   }       System.out.println("sum of digit is " +sum);    } } Input  - 5 Output  - 55 Explanation  - 1 2  + 2 2  + 3 2  + 4 2  + 5 2

Java Program to print sum of the square of each given digit

Image
 Java Program to print sum of the square of given digit  A program that accepts a positive number as input and calculates the sum of squares of individual digits of the given number. Java Program to print  sum of the square of given number by Do WHILE Loop Example Input and Output Format: Input consists of an integer. Enter the number : 23 2*2+3*3 Output consists of an integer. Sum of square of Digits is : 13 import java.util.Scanner; class SumofSqDigits { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the number:"); int n = sc.nextInt(); int sum = 0; do{ int a = n%10; sum = sum+a*a; n = n/10;       }while(n!=0); System.out.println("Sum of square of Digits is: "+sum); } } Sample Input: Enter the number: 32 Sample Output: Sum of square of Digits is: 13