Posts

Creating Subtraction App in Android Studio using Java and xml.

Image
 1. Creating Subtraction  App in Android Studio  using Java and xml. xml code for design:- <? xml version ="1.0" encoding ="utf-8" ?> <androidx.constraintlayout.widget.ConstraintLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" android :layout_height ="match_parent" tools :context =".MainActivity" > <EditText android :id ="@+id/etNum1" android :layout_width ="93dp" android :layout_height ="43dp" android :ems ="10" android :inputType ="number" app :layout_constraintBottom_toBottomOf ="parent" app :layout_constraintEnd_toEndOf ="parent" app :layout_constraintHorizontal_bias ="0.

Find even number between two number.

 14. Find even number between two number. package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here Scanner sc = new Scanner ( System . in ); int fist , second , evenN ; System . out . println ( "To find even number between two number " ); System . out . print ( "First number : " ); fist = sc . nextInt (); System . out . print ( "Second number : " ); second = sc . nextInt (); for ( int i = 1 ; i <= second ; i ++ ) { if ( i % 2 == 0 ) { System . out . print ( i + " " ); } } } } To find even number between two number First number : 13 Second number : 65 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 Process finished with exit code 0

Temperature Conversion System

Image
Temperature Conversion System   Temperature of city in Fahrenheit degrees is input through the keyboard. wr ite a program to convert this temperature into centigrade. package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here float fahrenheit , centigrade , temp ; int choice ; System . out . println ( "Temperature conversion system " ); System . out . println ( "1. Fahrenheit to Centigrade" ); System . out . println ( "2. Centigrade to Fahrenheit" ); System . out . print ( "your choice : " ); Scanner sc = new Scanner ( System . in ); choice = sc . nextInt (); if ( choice == 1 ) { System . out . print ( "Fahrenheit : " ); fahrenheit = sc . nextFloat (); centigrade = ( float ) ( - 17.2222222 * fahrenheit ); System . out . printl

Java coding question.

12. If  the marks obtained by student in five subject are input through the keyboard , write a program to find out the aggregate marks and percentage marks obtained  by a student in each subject is 100. package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here Scanner sc = new Scanner ( System . in ); int operating_System , DSA , DBMS , java , IOT , total ; float percentage ; System . out . println ( "Enter your marks " ); System . out . print ( "operating system : " ); operating_System = sc . nextInt (); System . out . print ( "DSA : " ); DSA = sc . nextInt (); System . out . print ( "DBMS : " ); DBMS = sc . nextInt (); System . out . print ( "Java : " ); java = sc . nextInt (); System . out . print ( "IOT : " ); IOT = sc . nextI

the distance between two cities (in km is input through the keyboard. write a program to convert and print this distance in meter ,feet inches and centimeter.

11 . The distance between two cities (in km is input through the keyboard. write a program to convert and print this distance in meter ,feet inches and centimeter. package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here System . out . print ( "Enter distance between two cities : " ); Scanner sc = new Scanner ( System . in ); //sc is scanner name double distance , meter , feet , inches , centimetres ; //variable is declared distance = sc . nextDouble (); //taking input from user (in km) meter = distance * 1000 ; //1km = 1000m feet = distance * 3280.8399 ; //1km = 3280.8399; inches = distance * 39370.0787 ; //1km = 39370.0787; centimetres = distance * 100000 ; //1km = 100000; System . out . println ( distance + " kilometer = " + meter + " meter" ); System . out . println ( distance + " k

Check vowel or constant in java

10. Check vowel or constant in java package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here Scanner sc = new Scanner ( System . in ); System . out . println ( "Enter alphabet to check alphabet is vowel or constant" ); char alphabet = sc . next (). charAt ( 0 ); if ( alphabet == 'a' || alphabet == 'e' || alphabet == 'i' || alphabet == 'o' || alphabet == 'u' ) { System . out . println ( alphabet + " is vowel" ); } else System . out . println ( alphabet + " is constant" ); } } output:- h is constant Process finished with exit code 0

convert int to char in java

 9. convert int to char in java package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here int a ; Scanner sc = new Scanner ( System . in ); System . out . println ( "Enter a number : " ); a = sc . nextInt (); char b = ( char ) a ; /*there might be a loss of data while converting from int to car. so ,we are using (char) to specify that a should be converted to character*/ System . out . println ( b ); } } output:- Enter a number : 80 P Process finished with exit code 0

Number is even or odd in java

  8 . Number is even or odd in java package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here int a ; Scanner sc = new Scanner ( System . in ); System . out . println ( "Find number is even or odd" ); System . out . print ( "Enter a number : " ); a = sc . nextInt (); if ( a % 2 == 0 ) { System . out . println ( "Even" ); } else System . out . println ( "Odd" ); } } output:- Find number is even or odd Enter a number : 23 Odd Process finished with exit code 0

Typecasting

  Typecasting Typecasting:- typecasting help to convert one data type to another data type //Typecasting package com.company ; public class Main { public static void main ( String [] args ) { // write your code here //int type variable int a = 33 ; System . out . println ( "int variable : " + a ); //convert int into double double c = a ; System . out . println ( "double variable is : " + c ); } } output:- int variable : 33 double variable is : 33.0 Process finished with exit code 0

find quotient and remainder in java

  find quotient and remainder //find quotient and remainder package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { int dividend , divisor , quotient , remainder ; Scanner ddqr = new Scanner( System . in ) ; System . out .print( "Enter dividend : " ) ; dividend = ddqr .nextInt() ; System . out .print( "Enter divisor : " ) ; divisor = ddqr .nextInt() ; quotient = dividend / divisor ; System . out .println( "Quotient is : " + quotient ) ; remainder = dividend % divisor ; System . out .println( "Remainder is : " + remainder ) ; } } output:- Enter dividend : 15 Enter divisor : 4 Quotient is : 3 Remainder is : 3 Process finished with exit code 0