Skip to content

Commit

Permalink
added coding challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
ananyachibber21 committed Sep 22, 2023
1 parent 6d5689b commit 4f519e3
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Java Coding Challenges/CC_01.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.*;

public class CC_01 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input: ");
int n1 = sc.nextInt();
int n2 = sc.nextInt();
int sum = n1 + n2;
int sub = n1 - n2;
int mul = n1 * n2;
int div = n1 / n2;
int mod = n1 % n2;
System.out.printf("Output: Sum: %d Sub: %d Mul: %d Div: %d Mod: %d", sum, sub, mul, div, mod);
}

}
18 changes: 18 additions & 0 deletions Java Coding Challenges/CC_02.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.*;

public class CC_02 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input: ");
int n = sc.nextInt();
if(n%2==0) {
System.out.print("Output: "+ "Even");
}
else {
System.out.print("Output: "+ "Odd");
}

}

}
12 changes: 12 additions & 0 deletions Java Coding Challenges/CC_03.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import java.util.Scanner;

public class CC_03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input: ");
float r = sc.nextFloat();
double area = 3.14*r*r;
System.out.println("Output: "+ area);
}

}
16 changes: 16 additions & 0 deletions Java Coding Challenges/CC_04.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.*;
public class CC_04 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input: ");
int n1 = sc.nextInt();
int n2 = sc.nextInt();
int n3;
n3 = n1;
n1 = n2;
n2 = n3;
System.out.printf("Output: n1=%d n2=%d", n1, n2);
}

}
18 changes: 18 additions & 0 deletions Java Coding Challenges/CC_05.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Scanner;
public class CC_05 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input: ");
int n1 = sc.nextInt();
int n2 = sc.nextInt();
if(n1>n2) {
System.out.printf("Min=%d Max=%d", n2, n1);
}
else {
System.out.printf("Min=%d Max=%d", n1, n2);
}

}

}
15 changes: 15 additions & 0 deletions Java Coding Challenges/CC_06.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import java.util.Scanner;
public class CC_06 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input: ");
int n1 = sc.nextInt();
int n2 = sc.nextInt();
int n3 = sc.nextInt();
int min = n1<n2 && n1<n3 ? n1 : n2<n1 && n2<n3 ? n2 : n3;
int max = n1>n2 && n1>n3 ? n1 : n2>n1 && n2>n3 ? n2 : n3;
System.out.printf("Min = %d Max = %d", min, max);
}

}
14 changes: 14 additions & 0 deletions Java Coding Challenges/CC_07.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Scanner;
public class CC_07 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input: ");
int n1 = sc.nextInt();
int n2 = sc.nextInt();
int n3 = sc.nextInt();
int second = n1>n2&&n1>n3?n2>n3?n2:n3 : n2>n1&&n2>n3?n1>n3?n1:n3 : n1>n2?n1:n2;
System.out.print("Output: " + second);
}

}
30 changes: 30 additions & 0 deletions Java Coding Challenges/CC_08.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.util.*;

public class CC_08 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = {3,6,4,0,1,5,6};
System.out.print("Original Array: ");
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i]+" ");
}
System.out.println();
int temp;
for(int i=0; i<arr.length; i++) {
for(int j=i+1; j<arr.length; j++) {
if(arr[i]>arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
System.out.println();
System.out.print("Sorted Array: ");
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i]+" ");
}
}

}

0 comments on commit 4f519e3

Please sign in to comment.