https://www.youtube.com/watch?v=9j3rnIImG9E
Posts
Showing posts from July, 2019
Check Prime Number Using Function in Java
- Get link
- X
- Other Apps
import java.util.*; class primefuntion { static boolean isprime(int n) { int i,c=0; for(i=1;i<=n;i++) { if(n%i==0) c++; } if(c==2) return true; else return false; } public static void main(String args[]) { int a; Scanner sc=new Scanner(System.in); System.out.println("Enter the value of a"); a=sc.nextInt(); if(isprime(a)) System.out.println("Prime"); else System.out.println("Not prime"); } }
WAP in Java to swap two given number
- Get link
- X
- Other Apps
import java.util.*; class swapp { public static void main(String args[]) { int a,b,t; Scanner sc=new Scanner(System.in); System.out.println("Enter a and b"); a=sc.nextInt(); b=sc.nextInt(); System.out.println("Before swapping"); System.out.println(a+" "+b); t=a; a=b; b=t; System.out.println("After swapping"); System.out.print(a+" "+b); } }
WAP TO FIND HCF AND LCM IN JAVA
- Get link
- X
- Other Apps
import java.util.*; class hcf { public static void main(String args[]) { int a,b,h=1,l,min,i; Scanner sc=new Scanner(System.in); System.out.println("Enter the a and b"); a=sc.nextInt(); b=sc.nextInt(); for(i=1;i<=a*b && i<=b*a;i++) { if(a%i==0 && b%i==0) { h=i; } } l=(a*b)/h; System.out.println("Hcf="+h); System.out.println("Lcm="+l); } }
SWITCH CASE IN JAVA
- Get link
- X
- Other Apps
import java.util.*; class switch1 { public static void main(String args[]) { int ch,a,b,c; Scanner sc=new Scanner(System.in); System.out.println("1.Addition \n 2.Substraction \n 3.Multiplication\n 4.Division \n5.Modation"); System.out.println("Enter your choice"); ch=sc.nextInt(); System.out.println("Enter the two no"); a=sc.nextInt(); b=sc.nextInt(); switch(ch) { case 1: c=a+b; System.out.println("Sum="+c); break; case 2: c=a-b; System.out.println("Sub="+c); break; case 3:
WAP in Java to decide whether the year is a leap year or not
- Get link
- X
- Other Apps
import java.util.*; class leap_year { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter a Year"); int year = sc.nextInt(); //condition for checking year entered by user is a leap year or not if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) System.out.println(year + " is a leap year."); else System.out.println(year + " is not a leap year."); } }
WAP to Find the Maximum and Minimum Digit given by the user
- Get link
- X
- Other Apps
import java.util.*; class smalldigitmaxdigit { public static void main(String args[]) { int a,n,d,min,max; Scanner sc=new Scanner(System.in); System.out.println("Enter the no"); n=sc.nextInt(); min=max=n%10; while(n!=0) { d=n%10; if(d>max) { max=d; //System.out.println("Maximum="+max); } else if(d<min) { min=d; //System.out.println("Minimum="+min); } n=n/10; } System.out.println("Maximum="+max); System.out.println("Minimum="+min); } }