Posts

Showing posts with the label java program

wap to make atm machine. #JAVA

import java.util.Scanner;  class AtmMachine  {     private static Scanner in ;     private static float balance = 0; // initial balance to 0 for everyone     private static int anotherTransaction;     public static void main(String args[]) {         in = new Scanner(System.in);         // call our transaction method here         transaction();     }     private static void transaction() {                  int choice;         System.out.println("Please select an option");         System.out.println("1. Withdraw");         System.out.println("2. Deposit");         System.out.println("3. Balance");         choice = in .nextInt();         switch (choice) {           ...

wap to calculate area of triangle

//wap to calculate area of triangle import java.util.Scanner; class triangle  {    public static void main(String args[])      {                  Scanner s= new Scanner(System.in);                   System.out.println("Enter the width of the Triangle:");          double b= s.nextDouble();            System.out.println("Enter the height of the Triangle:");           double h= s.nextDouble();                     //Area = (width*height)/2       double area=(b*h)/2;       System.out.println("Area of Triangle is: " + area);          } }

Java Program to find Power of a Number

// Java Program to find Power of a Number import java.util.Scanner; public class power  { private static Scanner sc; public static void main(String[] args)  { int number, i, exponent; long power = 1; sc = new Scanner(System.in); System.out.print(" Please Enter any Number : "); number = sc.nextInt(); System.out.print(" Please Enter the Exponent Value : "); exponent = sc.nextInt(); for(i = 1; i <= exponent; i++) { power = power * number; } System.out.println("\n The Final result of " + number + " power " + exponent + " = " + power); } }

wap to find a factorial of a number

public class factorial  {     public static void main(String[] args) {         int num = 10;         long factorial = 1;         for(int i = 1; i <= num; ++i)         {             // factorial = factorial * i;             factorial *= i;         }         System.out.printf("Factorial of %d = %d", num, factorial);     } }

wap to display a no is prime or not

import java.util.Scanner; public class prime {     public static void main(String args[])     {         int num, i, count=0;         Scanner scan = new Scanner(System.in);         System.out.print("Enter a Number : ");         num = scan.nextInt();         for(i=2; i<num; i++)         {             if(num%i == 0)             {                 count++;                 break;             }         }         if(count == 0)         {             System.out.print("This is a Prime Number");         }         else         {  ...

wap to read given no is pallindrome or not

import java.util.Scanner;   class Palindrome {    public static void main(String args[])    {       String str, rev = "";       Scanner sc = new Scanner(System.in);         System.out.println("Enter a string:");       str = sc.nextLine();         int length = str.length();         for ( int i = length - 1; i >= 0; i-- )          rev = rev + str.charAt(i);         if (str.equals(rev))          System.out.println(str+" is a palindrome");       else          System.out.println(str+" is not a palindrome");      } }

wap to display pattern in number

class NumberPattern {  public static void main(String[] args)   {  for (int i = 1; i <= 5; i++)   {  for (int j = 1; j <= i; j++)  {  System.out.print(j+" ");  }  System.out.println();  }  } }

wap to check number is fibonacci

import java.util.Scanner; class Fibonacci  { public static void main(String[] args)  { int i,no, first=0, second=1, next; Scanner s=new Scanner(System.in); System.out.println("Enter number of terms for Series: "); no=s.nextInt(); first=0; second=1; System.out.println("Fibonacci series are: ");  for(i=0; i<no; i++)  {   System.out.println(first);   next = first + second;   first = second;   second = next;   } } }

wap to check number is armstrong or not

import java.util.Scanner; class Armstrong  {  public static void main(String[] args) { int arm=0,a,b,c,d,no;  Scanner s=new Scanner(System.in); System.out.println("Enter any num :"); no=s.nextInt(); d=no; while(no>0) { a=no%10; no=no/10; arm=arm+a*a*a; } if(arm==d) { System.out.println("Armstrong :"); } else { System.out.println("not Armstrong"); } } }

wap to swapping of two numbers using third variable

//wap to swapping of two numbers import java.util.Scanner; class swapping { public static void main(String[] arg) { Scanner sc=new Scanner(System.in); System.out.println("Enter First Number : "); int x=sc.nextInt(); System.out.println("Enter second number : "); int y=sc.nextInt(); System.out.println("Before Swapping x ="+x +" y="+y); x=x+y; y=x-y; x=x-y; System.out.println("After Swapping x ="+x +" y="+y); } }

//wap to swap two values of 2nos

//wap to swap two values of 2nos import java.util.Scanner; public class swap1 {     public static void main(String[] args)      {     Scanner s=new Scanner(System.in);              int a=s.nextInt();         int b=s.nextInt();         System.out.println(a);         System.out.println(b);         a=a+b;         b=a-b;         a=a-b;         System.out.println(a);         System.out.println(b);     } }

//wap to read a number from a user and print there sum of first and last digits.

//wap to read a number from a user and print there sum of first and last digits. import java.util.Scanner; class sofal { public static void main(String[] arg) { Scanner sc=new Scanner(System.in); System.out.println("enter number "); int n=sc.nextInt(); int sum=0; int a=n%10; int rem=0; while(n>0) { rem=n%10; n=n/10; } sum=a+rem; System.out.println("Sum of digits ="+sum); } }

wap to find reminder and quotient

 class quotient  { public static void main(String[] args) { int dividend = 25, divisor = 4; int quotient = dividend / divisor; int remainder = dividend % divisor; System.out.println("Quotient = " + quotient); System.out.println("Remainder = " + remainder); } }

wap to find total marks,percentage of five subject

 class marks {     public static void main(String args[])      {         int maths,science,french,computer,sst;         maths=70;         science=50;         french=45;         computer=90;         sst=85;         double  SubjectTotal=500;         System.out.println ("maths="+maths);         System.out.println("science="+science);         System.out.println("french="+french );           System.out.println("computer="+computer);         System.out.println("sst="+sst);         double  TotalMarks=maths+science +french +computer +sst ;         System.out.println("total marks="+TotalMarks );         double  percentage=TotalMarks /SubjectTotal *100;...

//wap wheather a given number is leap year or not

//wap wheather a given number is leap year or not import java.util.Scanner; class leapyear { public static void main(String[] arg) { Scanner sc=new Scanner(System.in); System.out.println("Enter year : "); int year=sc.nextInt(); if(year%100==0) { if(year%400==0) System.out.println("Input year is leap year"); else System.out.println("Input  year is not leap year"); } else if(year%4==0) System.out.println("input year is leap year"); else System.out.println("input year is not leap year"); } }

/wap to check wheather an input even or odd

//wap to check wheather an input even or odd import java.util.Scanner; class even { public static void main(String[] arg) { Scanner sc=new Scanner(System.in); System.out.println("enter number "); int num=sc.nextInt(); if(num%2==0) { System.out.println("number is even"); } else { System.out.println("Input character is a odd"); } } }

// A program to find the cube of a number.

// A program to find the cube of a number.  import  java.util.Scanner; class cube {     public static void main(String[] arg)  {                                    Scanner sc = new Scanner(System.in);         System.out.println(" write any number:");         int d=sc.nextInt();                  System.out.println(d*d*d);                       } }

wap to wheather a number is character ya symbol

import java.util.Scanner; class character { public static void main(String[] arg) { Scanner sc=new Scanner(System.in); System.out.println("enter character : "); char ch=sc.next().charAt(0); if((ch>=65 && ch<=90) || (ch>=97 && ch<=122)) System.out.println("Input character is Alphabet"); else if(ch>=48 &&ch<=57) System.out.println("Input character is Digts"); else System.out.println("Input character is a Symbol"); } }

create a menu driven application to perform addition,subtraction,multiplicaltion and devision of two numbers.

 //create a menu driven application  to perform addition,subtraction,multiplicaltion and devision of two numbers. import java.util.Scanner; class calculator { public static void main(String[] arg) { Scanner sc=new Scanner(System.in); char c1; do{ System.out.print("Enter two number :"); int a=sc.nextInt(); int b=sc.nextInt(); System.out.println("\t\t----calculator choice Menu----\n"); System.out.println("\t\t\t 1 Addition"); System.out.println("\t\t\t 2 Subtraction"); System.out.println("\t\t\t 3 Multiplication"); System.out.println("\t\t\t 4 Division"); System.out.println("\n\t\t\t Enter choice : "); int ch=sc.nextInt(); switch(ch) { case 1: int s=a+b; System.out.println("Addition = "+s); break; case 2: int s1=a-b; System.out.println("Subtraction = "+s1); break; case 3: int s2=a*b; System.out.pri...

wap to read a number from a user and print there sum of digits.

//wap to read a number from a user and print there sum of digits. import java.util.Scanner; class assingment4 { public static void main(String[] arg) { Scanner sc=new Scanner(System.in); System.out.println("Enter number : "); int n=sc.nextInt(); int sum=0; while(n>0) { int rem=n%10; n=n/10; sum=sum+rem; } System.out.println("Sum of digits ="+sum); } }