Posts

Showing posts from May, 2023

Denomination of Notes

Image
  package textBookk01; // Denomination of Notes import java.util.Scanner; public class DenominationNotes01 { public static void main(String[] args ) { Scanner sc = new Scanner(System. in ); System. out .println( "Enter Amount :" ); int amount = sc .nextInt(); int denomination [] = {2000,500,200,100}; int notecount [] = new int [ denomination . length ]; for ( int i =0; i < denomination . length ; i ++) { if ( amount >= denomination [ i ]) { notecount [ i ] = amount / denomination [ i ]; amount = amount % denomination [ i ]; } } System. out .println( "Denomainton count :" ); for ( int i =0; i < denomination . length ; i ++) { System. out .println( denomination [ i ]+ " * " + notecount [ i ]); } } } ------------------------------------------------ for ( int   i =0; i < denomination . length ; i ++) {      if ( amount  >= denominat

Calculate Electricity Bill

  Write a program to calculate the electricity bill (accept number of unit from user) according to the following criteria : Unit Price First 100 units no charge Next 100 units Rs 5 per unit After 200 units Rs 10 per unit (For example if input unit is 350 than total bill amount is Rs2000) public class q55 { public static void main(String[] args ) { Scanner sc = new Scanner(System. in ); System. out .println( "Enter the units" ); int unit = sc .nextInt(); int bill = 0; if ( unit > 200) { bill = bill + ( unit - 200) * 10; // bill goes downward direction unit = 200; } if ( unit > 100) { bill = bill + ( unit - 100) * 5; // (unit -100)(200 - 100) upper 200 unit get unit = 100; } if ( unit > 0) { bill = bill + unit * 0; } System. out .println( bill ); } } -------------------------------------- here, unit e.g. = 201, flows goes downward dir

Number to Words Convert

Image
  number to Words Convert public class NumberToWord { public static void main(String[] args ) {      Scanner sc = new Scanner(System. in );      System. out .print( "Enter a number (0 to 999): " );      int num = sc .nextInt();      System. out .println( "Number in words: " + convertToWord ( num )); } public static String convertToWord( int num ) { String[] units = { "Zero" , "One" , "Two" , "Three" , "Four" , "Five" , "Six" , "Seven" , "Eight" , "Nine" , "Ten" , "Eleven" , "Twelve" , "Thirteen" , "Fourteen" , "Fifteen" , "Sixteen" , "Seventeen" , "Eighteen" , "Nineteen" }; String[] tens = { "" , "" , "Twenty" , "Thirty" , "Forty" , "Fifty" , &qu

Integer Convert Into String

  Integer Convert into String public class convertIntToStringWitInBuMeth {      public static String intToString( int n ) {      String result = "" ;      boolean isNegative = false ;      if ( n < 0) {      isNegative = true ;      n = - n ; // convert negative value into positive      }      if ( n == 0) {      result = "0" ;      } else {      while ( n > 0) {      int digit = n % 10;      char digitChar = ( char ) ( digit + '0' );      result = digitChar + result ;      n /= 10;      } }      if ( isNegative ) {      result = '-' + result ;      }      return result ; }      public static void main(String[] args ) {      int n = 12;      String s = intToString ( n );     

Find Prime Numbers In Array

prime numbers in arrays => Correct way :   public class q34 { public static void main(String[] args ) {      int a [] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };      int n ;      String primes = "" ;      for ( int i = 0; i < a . length ; i ++) {      int counter = 0;      for ( n = a [ i ]; n >= 1; n --) {      if ( a [ i ] % n == 0) {      counter ++;      } }      if ( counter == 2) {      primes = primes + a [ i ] + " " ;      } }      System. out .println( primes );      } } ----------------------------------------------- e.g : a[i]= 3;   0 = 1 count;     3 2 1     3 / 3 = 0 , 3 / 2 = 1 , 3 / 1 = 0     two zero means prime