-
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
Showing
19 changed files
with
422 additions
and
0 deletions.
There are no files selected for viewing
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,35 @@ | ||
package Beginner; | ||
|
||
// The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains two Integers A and B. | ||
import java.util.*; | ||
class AddTwoNumbers { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
int a = sc.nextInt();//Enter number of inputs | ||
int n1 = 0; | ||
int n2 = 0; | ||
|
||
int i = 1; | ||
int j =0; | ||
while (i<=a) { | ||
|
||
while (j<=2) { | ||
n1 = sc.nextInt();//enter first number | ||
n2 = sc.nextInt();//enter second number | ||
System.out.println(n1 + n2); | ||
j++; | ||
} | ||
i++; | ||
} | ||
sc.close(); | ||
|
||
} | ||
} | ||
|
||
// for(int i = 1; i<=a; i++){ | ||
// for(int j = 1; j<=2;j++){ | ||
// n1 = sc.nextInt(); | ||
// n2 = sc.nextInt(); | ||
// System.out.println(n1 + n2); | ||
|
||
// } |
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 @@ | ||
// Chef went to a shop and buys a pens and b pencils. Each pen costs x units and each pencil costs y units. | ||
// Now find what is the total amount Chef will spend to buy a pens and b pencils. | ||
import java.util.*; | ||
class BuyPlease { | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
int a = sc.nextInt(); | ||
int b = sc.nextInt(); | ||
int x = sc.nextInt(); | ||
int y = sc.nextInt(); | ||
int sum = a*x + b*y; | ||
System.out.println(sum); | ||
sc.close(); | ||
} | ||
} |
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 @@ | ||
// You are given a number N and find all the distinct factors of N. | ||
import java.util.*; | ||
class FactorFinding { | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
int N = sc.nextInt(); // Enter N | ||
int sum = 0; | ||
String factors = ""; | ||
for(int i = 1; i<=N; i++){ | ||
if(N%i == 0){ | ||
sum++; | ||
//System.out.print(i +" "); | ||
factors +=(i + " "); | ||
} | ||
} | ||
// number of factor found | ||
System.out.println(sum); | ||
System.out.println(factors); | ||
sc.close(); | ||
} | ||
} | ||
// completed |
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 @@ | ||
// You're given a number N. If N is divisible by 5 or 11 but not both then print "ONE"(without quotes). | ||
// If N is divisible by both 5 and 11 then print "BOTH"(without quotes). If N is not divisible by 5 or 11 then print "NONE"(without quotes). | ||
import java.util.*; | ||
class IsBothOrNot { | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
int N = sc.nextInt(); | ||
if(N%5 == 0 && N%11 == 0){ | ||
System.out.println("BOTH"); | ||
}else if(N%5 == 0 || N % 11 == 0){ | ||
System.out.println("ONE"); | ||
}else{ | ||
System.out.println("NONE"); | ||
} | ||
sc.close(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
CodeShef/Easy Problems to Get Started/addNaturalNumbers.java
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 @@ | ||
//You are given a number N. Find the sum of all numbers from 1 to N. | ||
import java.util.*; | ||
class addNaturalNumbers { | ||
public static void main(String[] args) { | ||
|
||
Scanner sc = new Scanner(System.in); | ||
int n = sc.nextInt();//enter n | ||
int a = 0; | ||
int i = 1; | ||
// for(int i = 1; i<=n;i++){ | ||
// a=a+i;//a will be keep on adding until loop ends | ||
// } | ||
// System.out.println(a); | ||
while (i<=n) { | ||
a =a +i; | ||
i = i+1; | ||
} | ||
System.out.println(a); | ||
sc.close(); | ||
} | ||
} | ||
//complete |
33 changes: 33 additions & 0 deletions
33
CodeShef/Easy Problems to Get Started/alternativeSquare.java
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,33 @@ | ||
// You're given a number N. Print the first N lines of the below-given pattern. | ||
|
||
// 1 2 3 4 5 | ||
// 10 9 8 7 6 | ||
// 11 12 13 14 15 | ||
// 20 19 18 17 16 | ||
// 21 22 23 24 25 | ||
// 30 29 28 27 26 | ||
import java.util.*; | ||
class alternativeSquare { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
int n = sc.nextInt(); | ||
int count = 0; | ||
for(int i = 1; i<=n; i++){ | ||
if(i%2 != 0 ){ | ||
for(int j = 1;j<=5; j++){ | ||
count = count + 1; | ||
System.out.print(count + " "); | ||
} | ||
}else { | ||
int temp = count+1; | ||
for(int j = count+5; j>=temp; j--){ | ||
count = count + 1; | ||
System.out.print(j +" "); | ||
} | ||
} | ||
System.out.println(); | ||
} | ||
sc.close(); | ||
} | ||
} | ||
//complete |
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,28 @@ | ||
//You are given a list of N integers and a value K. Print 1 if K exists in the given list of N integers, otherwise print −1. | ||
import java.util.*; | ||
class findMe { | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
int n = sc.nextInt();// enter size | ||
int k = sc.nextInt();//enter number to find | ||
int integers[] = new int[n]; | ||
String answer = ""; | ||
String notanswer = ""; | ||
for(int i = 0; i<n; i++){ | ||
integers[i] = sc.nextInt();// enter data | ||
if(integers[i]==k){ | ||
answer = "1"; | ||
}else { | ||
notanswer = "-1"; | ||
} | ||
} | ||
if(answer == "1"){ | ||
System.out.println(answer); | ||
} | ||
if(answer !="1"){ | ||
System.out.println(notanswer); | ||
} | ||
sc.close(); | ||
} | ||
} | ||
// complete |
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 @@ | ||
//Raju is planning to visit his favourite restaurant. He shall travel to it by bus. | ||
//Only the buses whose numbers are divisible by 5 or by 6 shall take him to his destination. | ||
// You are given a bus number N. Find if Raju can take the bus or not. Print YES if he can take the bus, otherwise print NO | ||
import java.util.*; | ||
class rajuTrip { | ||
public static void main(String argsp[]){ | ||
Scanner sc = new Scanner(System.in); | ||
int n = sc.nextInt(); | ||
if(n%5 == 0 || n%6 == 0){ | ||
System.out.println("YES"); | ||
}else{ | ||
System.out.println("NO"); | ||
} | ||
sc.close(); | ||
} | ||
} | ||
// complete |
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 @@ | ||
// You're given two numbers L and R. | ||
// Print all odd numbers between L and R (both inclusive) in a single line separated by space, in ascending (increasing) order. | ||
import java.util.*; | ||
class rangeOdd{ | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
int l = sc.nextInt(); | ||
int r = sc.nextInt(); | ||
for(int i = l; i<=r; i++){ | ||
if(i%2 != 0){ | ||
System.out.println(i); | ||
} | ||
} | ||
sc.close(); | ||
} | ||
} |
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 @@ | ||
// You are given a list of N integers and you need to reverse it and print the reversed list in a new line | ||
import java.util.*; | ||
class reverseMe { | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
int n = sc.nextInt();// enter size | ||
int integers[] = new int[n]; | ||
for(int i = 0; i<n; i++){ | ||
integers[i] = sc.nextInt();// enter data | ||
} | ||
for(int i = n-1; i>=0; i--){ | ||
System.out.print(integers[i] + " "); | ||
} | ||
sc.close(); | ||
} | ||
} | ||
// complete |
24 changes: 24 additions & 0 deletions
24
CodeShef/Easy Problems to Get Started/reverseStarPattern.java
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,24 @@ | ||
// You're given a number N. Print the first N lines of the below-given pattern. | ||
|
||
// * | ||
// ** | ||
// *** | ||
// **** | ||
// ***** | ||
import java.util.*; | ||
class reverseStarPattern { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
int n = sc.nextInt(); | ||
for(int i=1; i<=n; i++){ | ||
for(int j = n-i; j>=1; j--){ | ||
System.out.print(" "); | ||
} | ||
for(int j = 1;j<=i;j++){ | ||
System.out.print("*"); | ||
} | ||
System.out.println(); | ||
} | ||
sc.close(); | ||
} | ||
} |
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,24 @@ | ||
// Given three distinct integers A, B and C, print the second largest number among them. | ||
import java.util.*; | ||
class secondLargest { | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
int a = sc.nextInt(); | ||
int b = sc.nextInt(); | ||
int c = sc.nextInt(); | ||
if(a>b && b>c){// a=3 b=2 c=1 | ||
System.out.println(b); | ||
}else if(c>b && b>a){ // a=1 b=2 c=3 | ||
System.out.println(b); | ||
}else if(a>c && c>b){ // a= 3 b=1 c= 2 | ||
System.out.println(c); | ||
}else if(b>c && c>a){ //a =1 b=3 c=2 | ||
System.out.println(c); | ||
}else if(c>a && a>b){// a =2 b=1 c= 3 | ||
System.out.println(a); | ||
}else if(b>a && a>c){// a=2 b=3 c=1 | ||
System.out.println(a); | ||
} | ||
sc.close(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
CodeShef/Easy Problems to Get Started/triangleEverywhere.java
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,34 @@ | ||
//You're given the length of three sides a, b, and c respectively | ||
//Now If these three sides can form an Equilateral Triangle then print 1, | ||
// if these three sides can form an Isosceles Triangle then print 2, | ||
// if these three sides can form a Scalene Triangle then print 3, otherwise print −1. | ||
import java.util.*; | ||
class triangleEverywhere { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
double a = sc.nextInt(); | ||
double b = sc.nextInt(); | ||
double c = sc.nextInt(); | ||
double s = (a+b+c)/2; | ||
double area = s*(s-a)*(s-b)*(s-c); | ||
area = Math.sqrt(area); | ||
if(area>0){ | ||
if(a==b&&b==c){ | ||
System.out.println("1"); | ||
}else if(a==b&&b!=c){ | ||
System.out.println("2"); | ||
}else if(a==c&&c!=a){ | ||
System.out.println("2"); | ||
}else if(b==c&&a!=c){ | ||
System.out.println("2"); | ||
}else if(a!=b&&b!=c){ | ||
System.out.println("3"); | ||
} | ||
} | ||
else{ | ||
System.out.println("-1"); | ||
} | ||
sc.close(); | ||
} | ||
} | ||
//complete |
18 changes: 18 additions & 0 deletions
18
CodeShef/Easy Problems to Get Started/validAngleTriangle.java
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,18 @@ | ||
//You're given the three angles a, b, and c respectively. | ||
// Now check if these three angles can form a valid triangle with an area greater than 0 or not. | ||
// Print "YES"(without quotes) if it can form a valid triangle with an area greater than 0, otherwise print "NO" (without quotes). | ||
import java.util.*; | ||
class validAngleTriangle { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
int a = sc.nextInt(); | ||
int b = sc.nextInt(); | ||
int c = sc.nextInt(); | ||
int sum = a+b+c; | ||
if(sum == 180){ | ||
}else{ | ||
System.out.println("NO"); | ||
} | ||
sc.close(); | ||
} | ||
} |
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 @@ | ||
//You're given the length of three sides a, b, and c respectively. | ||
//Now check if these three sides can form a triangle or not. | ||
//Print "YES"(without quotes) if it can form a valid triangle with an area greater than 0, otherwise print "NO" (without quotes). | ||
import java.util.*; | ||
class validTriangle{ | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
double a = sc.nextInt(); | ||
double b = sc.nextInt(); | ||
double c = sc.nextInt(); | ||
double s = (a+b+c)/2; | ||
double area = (s*(s-a)*(s-b)*(s-c)); | ||
area = Math.sqrt(area); | ||
if(area>0){ | ||
System.out.println("YES"); | ||
}else{ | ||
System.out.println("NO"); | ||
} | ||
sc.close(); | ||
} | ||
} | ||
//complete |
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,21 @@ | ||
import java.util.*; | ||
public class INTRDSGN { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
int T = sc.nextInt(); | ||
for (int i = 0; i < T; i++) { | ||
int x1 = sc.nextInt(); | ||
int y1 = sc.nextInt(); | ||
int x2 = sc.nextInt(); | ||
int y2 = sc.nextInt(); | ||
int sum1 = x1+y1; | ||
int sum2 = x2+y2; | ||
if(sum1<=sum2){ | ||
System.out.println(sum1); | ||
}else{ | ||
System.out.println(sum2); | ||
} | ||
} | ||
sc.close(); | ||
} | ||
} |
Oops, something went wrong.