-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b569ce4
commit 900d4fc
Showing
23 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import java.util.*; | ||
public class CfcA1 { | ||
public static void main(String[] args){ | ||
Scanner sc = new Scanner(System.in); | ||
int credits; | ||
System.out.println("Enter the credits"); | ||
credits = sc.nextInt(); | ||
if(credits>=7500){ | ||
System.out.println("Tera Leader"); | ||
} | ||
else if(credits>=6000){ | ||
System.out.println("Gega Leader"); | ||
} | ||
else if(credits>=4500){ | ||
System.out.println("Mega Leader"); | ||
} | ||
else{ | ||
System.out.println("Rising Star"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import java.util.*; | ||
public class CfcA2 { | ||
public static void main(String[] args){ | ||
int amt,r,t,si; | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("Enter the amount, rate & time"); | ||
amt = sc.nextInt(); | ||
r = sc.nextInt(); | ||
t = sc.nextInt(); | ||
si = (amt*r*t)/100; | ||
System.out.println("Simple Interest :"+si); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import java.util.*; | ||
public class CfcA3 { | ||
public static void main(String[] args){ | ||
Scanner sc=new Scanner(System.in); | ||
int a,b,gcd=0; | ||
System.out.println("Enter two numbers"); | ||
a = sc.nextInt(); | ||
b = sc.nextInt(); | ||
for(int i=1; i<=a && i<=b; i++){ | ||
if(a%i==0 && b%i==0) | ||
gcd=i; | ||
} | ||
System.out.println("GCD is:"+gcd); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class CfcA4 { | ||
public static void main(String[] args){ | ||
int n=5,i=0,j=0,s=2; | ||
while(i!=n){ | ||
s=s+j; | ||
System.out.print(s + ","); | ||
i++; | ||
j=4*i; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import java.util.*; | ||
public class CfcA5 { | ||
public static void main(String[] args){ | ||
Scanner sc = new Scanner(System.in); | ||
int n, count=0; | ||
System.out.println("Enter the number"); | ||
n= sc.nextInt(); | ||
while(n!=0){ | ||
n=n/10; | ||
count++; | ||
} | ||
System.out.println("The number of digits:"+count); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import java.util.*; | ||
public class CfcA6 { | ||
public static void main(String[] args){ | ||
int n,rev=0; | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("Enter a number"); | ||
n = sc.nextInt(); | ||
while(n!=0){ | ||
rev=rev*10 + n%10; | ||
n=n/10; | ||
} | ||
System.out.println(rev); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
public class BaseConversion { | ||
public static void decToBin(int n){ | ||
int ans=0,pow=0; | ||
while(n != 0){ | ||
ans = (int)Math.pow(10, pow) * (n % 2)+ans; | ||
pow++; | ||
n = n/2; | ||
} | ||
System.out.println(ans); | ||
} | ||
public static void binToDec(int n){ | ||
int ans=0,pow=0; | ||
while(n != 0){ | ||
ans = (int)Math.pow(2, pow) * (n % 10)+ans; | ||
pow++; | ||
n= n/10; | ||
} | ||
System.out.println(ans); | ||
} | ||
public static void decToOctal(int n){ | ||
int ans=0,pow=0; | ||
while(n != 0){ | ||
ans = (int)Math.pow(10, pow) * (n % 8)+ans; | ||
pow++; | ||
n = n/8; | ||
} | ||
System.out.println(ans); | ||
} | ||
public static void octalToDec(int n){ | ||
int ans=0,pow=0; | ||
while(n != 0){ | ||
ans = (int)Math.pow(8, pow) * (n % 10)+ans; | ||
pow++; | ||
n = n/10; | ||
} | ||
System.out.println(ans); | ||
} | ||
public static void main(String args[]){ | ||
decToBin(19); | ||
binToDec(10011); | ||
decToOctal(154); | ||
octalToDec(232); | ||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import java.util.*; | ||
public class CheckChar { | ||
public static void main(String[] args){ | ||
Scanner sc = new Scanner(System.in); | ||
char ch; | ||
System.out.println("Enter a character"); | ||
ch = sc.next().charAt(0); | ||
if(ch>='A' && ch<='Z') | ||
System.out.println("Upper Case"); | ||
else if(ch>='a' && ch<='z') | ||
System.out.println("Lower Case"); | ||
else{ | ||
System.out.println("Invalid Input"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class CheckSortedOrNot { | ||
public static void main(String[]args){ | ||
int flag=0; | ||
int arr[]={13,25,45,55,62,79,2,94}; | ||
for(int i=0;i<arr.length-1;i++){ | ||
if(arr[i+1]<arr[i]) | ||
flag++; | ||
} | ||
if(flag==0){ | ||
System.out.println("Sorted"); | ||
} | ||
else{ | ||
System.out.println("Not Sorted"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import java.util.*; | ||
public class GCDnLCM { | ||
public static void gcd(int a,int b){ | ||
int ans = 0; | ||
for(int i=2;i<=a && i<=b;i++){ | ||
if(a % i ==0 && b % i ==0) | ||
ans = i; | ||
} | ||
System.out.println("GCD is "+ ans); | ||
} | ||
public static void lcm(int a,int b){ | ||
int i,max; | ||
max = (int)Math.max(a,b); | ||
while(true){ | ||
if(max % a == 0 && max % b == 0){ | ||
System.out.println("LCM is "+max); | ||
break; | ||
} | ||
max++; | ||
} | ||
} | ||
public static void main(String[]args){ | ||
int a,b; | ||
Scanner sc = new Scanner(System.in); | ||
a = sc.nextInt(); | ||
b = sc.nextInt(); | ||
gcd(a,b); | ||
lcm(a,b); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import java.util.*; | ||
public class PairSum { | ||
public static void checkPairSum(int arr[],int target){ | ||
for(int i=0;i<arr.length;i++){ | ||
for(int j=i+1;j<arr.length;j++){ | ||
if(arr[i]+arr[j]==target){ | ||
System.out.println(arr[i]+","+arr[j]); | ||
} | ||
} | ||
} | ||
} | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
int arr[]=new int[10]; | ||
int target; | ||
System.out.println("Enter the values in an array"); | ||
for(int i=0;i<arr.length;i++){ | ||
arr[i]=sc.nextInt(); | ||
} | ||
System.out.println("Enter the target value"); | ||
target=sc.nextInt(); | ||
checkPairSum(arr,target); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import java.util.*; | ||
public class ReverseAnum { | ||
public static void main(String[] args){ | ||
int n,rev=0; | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("Enter a number"); | ||
n = sc.nextInt(); | ||
while(n!=0){ | ||
rev=rev*10 + n%10; | ||
n=n/10; | ||
} | ||
System.out.println(rev); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class SortBinArr { | ||
public static void main(String[]args){ | ||
int arr[]={0,1,0,1,1,0,1,0,1,1,1,0,0,0,1}; | ||
for(int i=0;i<arr.length;i++){ | ||
for(int j=0;j<arr.length-1;j++){ | ||
if(arr[j]==1&&arr[j+1]==0){ | ||
arr[j+1]=1; | ||
arr[j]=0; | ||
} | ||
} | ||
} | ||
for(int i=0;i<arr.length;i++){ | ||
System.out.print(arr[i]+" "); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.util.*; | ||
public class calculator { | ||
public static void main(String[] args){ | ||
Scanner sc = new Scanner(System.in); | ||
int n1,n2; | ||
char ch; | ||
System.out.println("Enter two numbers"); | ||
n1 = sc.nextInt(); | ||
n2 = sc.nextInt(); | ||
System.out.println("Enter ch"); | ||
ch = sc.next().charAt(0); | ||
switch(ch){ | ||
case '*': | ||
System.out.println(n1*n2); | ||
break; | ||
case '/': | ||
System.out.println(n1/n2); | ||
break; | ||
case '%': | ||
System.out.println(n1%n2); | ||
break; | ||
case '+': | ||
System.out.println(n1+n2); | ||
break; | ||
case '-': | ||
System.out.println(n1-n2); | ||
break; | ||
default: | ||
System.out.println("invalid input"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import java.util.*; | ||
public class countMultipleOfn { | ||
public static void main(String[]args){ | ||
Scanner sc = new Scanner(System.in); | ||
int arr[] = new int[10]; | ||
System.out.println("Enter elements of the array:"); | ||
for(int i = 0;i < arr.length;i++){ | ||
arr[i] = sc.nextInt(); | ||
} | ||
int c=0; | ||
for(int i = 0;i < arr.length;i++){ | ||
if(arr[i]%5==0) | ||
c++; | ||
} | ||
System.out.println( "count"+c); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.util.*; | ||
public class countPrimeNum { | ||
public static boolean isPrime(int n){ | ||
if (n < 2) { | ||
return false; | ||
} | ||
for (int i = 2; i <= Math.sqrt(n); i++) { | ||
if (n % i == 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
public static int countPrime(int [] arr){ | ||
int count = 0; | ||
for (int i = 0; i < arr.length; i++) { | ||
if (isPrime(arr[i])) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
public static void main(String[]args){ | ||
Scanner sc = new Scanner(System.in); | ||
int arr[] = new int[10]; | ||
System.out.println("Enter elements of the array:"); | ||
for(int i = 0;i < arr.length;i++){ | ||
arr[i] = sc.nextInt(); | ||
} | ||
System.out.println("Count:"+ countPrime(arr)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class reverseAnArr { | ||
public static void main(String[]args){ | ||
int arr[]={4,1,75,9,8,6,0,2}; | ||
int temp,l=0,h=arr.length-1; | ||
while(l<h){ | ||
temp=arr[l]; | ||
arr[l]=arr[h]; | ||
arr[h]=temp; | ||
l++; | ||
h--; | ||
|
||
} | ||
for(int ele: arr){ | ||
System.out.println(ele); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
public class sortOddnEven { | ||
public static void sort(int arr[]){ | ||
for(int i=0;i<arr.length;i++){ | ||
for(int j=0;j<arr.length-i-1;j++){ | ||
if(arr[j]%2!=0 && arr[j+1]%2==0){ | ||
int temp=arr[j]; | ||
arr[j]=arr[j+1]; | ||
arr[j+1]=temp; | ||
} | ||
} | ||
} | ||
for(int ele: arr){ | ||
System.out.println(ele); | ||
} | ||
|
||
} | ||
public static void main(String[]args){ | ||
int arr[]={3,8,5,13,6,12,18,5}; | ||
sort(arr); | ||
} | ||
|
||
} |
Oops, something went wrong.