Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions December 01/dec1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.Scanner;
public class dec1 {
public static void main(String[] args) {
int[] cricket = new int[11];
int score = 0;
int best_batsmen = 0;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of batsmen:");
int n = scanner.nextInt();

for (int i = 0; i < n; i++) {
System.out.print("Enter runs scored by batsmen " + (i + 1) + ":");
cricket[i] = scanner.nextInt();
score = score + cricket[i];
}
int largest = cricket[0];
for (int i = 1; i < n; i++) {
if (cricket[i] > largest) {
largest = cricket[i];
best_batsmen = i;
}
}
System.out.println("Total runs scores by the team is " + score + " and the best batsmen is "
+ (best_batsmen + 1) + " .He scored " + largest + " Runs!!");
scanner.close();
}
}
38 changes: 38 additions & 0 deletions December 02/dec2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.Scanner;
public class dec2 {
public class december2 {
public static void main(String[] args) {
System.out.println("Enter number of Purchase to analyse : ");
Scanner scanner = new Scanner(System.in);
int size = scanner.nextInt();
int[] productId = new int[size];
System.out.println("Enter product ID ");
for(int i=0;i<size;i++){
System.out.println("No " + (i+1) + ":");
productId[i] = scanner.nextInt();
}
int[] frequencyArray = new int[size];
boolean[] visited = new boolean[size];
for (int i = 0; i < size; i++) {
if (!visited[i]) {
int count = 1;
for (int j = i + 1; j < size; j++) {
if (productId[i] == productId[j]) {
visited[j] = true;
count++;
}
}
frequencyArray[i] = count;
}
}
System.out.println("Frequency of each element:");
for (int i = 0; i < size; i++) {
if (!visited[i]) {
System.out.println(productId[i] + ": " + frequencyArray[i] + " times");
}
}
scanner.close();
}
}
}

26 changes: 26 additions & 0 deletions December 03/dec3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;
public class dec3 {
public class december3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Number of buildings : ");
int size = scanner.nextInt();
int[] array = new int[size];
System.out.println("Enter hight of the building:");

for (int i = 0; i < size; i++) {
System.out.print("Building " + (i + 1) + ": ");
array[i] = scanner.nextInt();
}
int count = 0;
for (int i = 1; i < size; i++) {
if (array[i] > array[i - 1]) {
count++;
}
}
System.out.println("No of building that can see the Sun rise ! : " + (count + 1));
scanner.close();
}
}

}
32 changes: 32 additions & 0 deletions December 04/dec4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Scanner;
public class dec4 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a word: ");
String word = scanner.nextLine();
String smallestPalindrome = findSmallestPalindrome(word);
System.out.println("Smallest palindrome: " + smallestPalindrome);
scanner.close();
}
private static String findSmallestPalindrome(String word) {
int length = word.length();

for (int i = 0; i < length; i++) {
for (int j = i + 1; j <= length; j++) {
String substring = word.substring(i, j);
if (isPalindrome(substring)) {
return substring;
}
}
}

return "No palindrome found";
}

private static boolean isPalindrome(String str) {
str = str.replaceAll("\\s", "").toLowerCase();
return str.equals(new StringBuilder(str).reverse().toString());
}
}


26 changes: 26 additions & 0 deletions December 05/dec5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;
public class dec5 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of stealing attempts :");
int n = scanner.nextInt();
int tot=0,money=0;
int[] array = new int[n];
for(int i=0;i<n;i++){
System.out.println("enter amount stolen in" + (i+1) + "th attempt");
int v =scanner.nextInt();
array[i]= v;
tot = tot+v;

}
int avg =tot/n;
for(int i=0;i<n;i++){
if(array[i]>=avg){
money= money + array[i];
}
}
System.out.println("the total amount of money stolen by the thieves who stole more than or equal to the average amount stolen by the group="+money);
scanner.close();
}
}
//retry
37 changes: 37 additions & 0 deletions December 06/dec6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.ArrayList;
import java.util.Scanner;

public class dec6 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of words in the secret msg:");
int n = scanner.nextInt();
String[] array = new String[n];
for (int i = 0; i < n; i++) {
System.out.println("Enter word no " + (i + 1));
String v = scanner.next();
array[i] = v;
}
ArrayList<String> finalList = new ArrayList<>();
finalList.add(array[0]);

for (int i = 1; i < n; i++) {
String a = finalList.get(finalList.size() - 1);
String b = array[i];
int m = 0;

for (int x = 0; x < a.length(); x++) {
if (a.charAt(x) != b.charAt(x)) {
m++;
}
}

if (m <= 1) {
finalList.add(b);
}
}

System.out.println(finalList);
scanner.close();
}
}
28 changes: 28 additions & 0 deletions December 07/dec7.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.Scanner;
public class dec7 {
public static void main(String[] args) {
Scanner scanner=new Scanner (System.in);
System.out.print("Enter the width of the rectangle: ");
double width = scanner.nextDouble();
System.out.print("Enter the height of the rectangle: ");
double height = scanner.nextDouble();
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();

boolean canFit = isRectangleInCircle(width, height, radius);
if (canFit) {
System.out.println("The rectangle can fit inside the circle.");
} else {
System.out.println("The rectangle cannot fit inside the circle.");
}

scanner.close();
}

private static boolean isRectangleInCircle(double width, double height, double radius) {
double diagonal = Math.sqrt(width * width + height * height);
return diagonal <= (2 * radius);
}
}


64 changes: 64 additions & 0 deletions December 08/dec8.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import java.util.Scanner;
public class dec8 {
public static void main(String[] args) {

System.out.print("Enter number of Rows/column for the square matrix:");
Scanner scanner= new Scanner(System.in);
int n= scanner.nextInt();
int[][] magicSquare = findPath(n);

displayMagicSquare(magicSquare);
scanner.close();
}



private static int[][] findPath(int n) {
int[][] magicSquare = new int[n][n];
int i = n / 2;
int j = n - 1;

for (int num = 1; num <= n * n;) {
if (i == -1 && j == n) {
j = n - 2;
i = 0;
} else {
if (j == n) {
j = 0;
}
if (i < 0) {
i = n - 1;
}
}
if (magicSquare[i][j] != 0) {
j -= 2;
i++;
continue;
} else {

magicSquare[i][j] = num++;
}

j++;
i--;
}
return magicSquare;
}



private static void displayMagicSquare(int[][] magicSquare) {
System.out.println("Magic Square:");

for (int i = 0; i < magicSquare.length; i++) {
for (int j = 0; j < magicSquare[i].length; j++) {
System.out.print(magicSquare[i][j] + "\t");
}
System.out.println();
}

}



}
23 changes: 23 additions & 0 deletions December 09/dec9.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;

public class dec9 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the camel case string: ");
String camelCaseString = scanner.next();

int wordCount = 1;
for (int i = 0; i < camelCaseString.length(); i++) {
char currentChar = camelCaseString.charAt(i);


if (Character.isUpperCase(currentChar)) {
wordCount++;
}
}
System.out.println("Number of words: " + wordCount);

scanner.close();
}
}
16 changes: 16 additions & 0 deletions December 10/dec10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class dec10 {
public static void main(String[] args) {

String[] empData = {"100 Shivnash Kumar", "110 Ragul Gupta"};

for (String empRecord : empData) {
String empnameSubstring = getEmpnameSubstring(empRecord);
System.out.println(empnameSubstring);
}
}
private static String getEmpnameSubstring(String empRecord) {

int empnameStartIndex = empRecord.indexOf(" ") + 1;
return empRecord.substring(empnameStartIndex);
}
}
13 changes: 13 additions & 0 deletions December 11/dec11.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import java.util.Scanner;
public class dec11 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter 2 Numbers : ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
int sum = num1+num2;
System.out.println("Sum in binary: " + Integer.toBinaryString(sum));
scanner.close();
}
}

33 changes: 33 additions & 0 deletions December 12/dec12.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.Arrays;
import java.util.Scanner;
public class dec12 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the content of Box1 seperated by coma: ");
String[] box1 = scanner.nextLine().split(", ");
System.out.print("Enter the content of Box2 : ");
String[] box2 = scanner.nextLine().split(", ");
System.out.print("Enter the content of Box3 : ");
String[] box3 = scanner.nextLine().split(", ");
String result = findGoldBox(box1, box2, box3);

System.out.println(result);

scanner.close();
}
private static String findGoldBox(String[] box1, String[] box2, String[] box3) {
String[] sortedBoxes = {box1[2], box2[2], box3[2]};

Arrays.sort(sortedBoxes);

if (sortedBoxes[1].equals("Gold")) {
return "The box containing the Gold is Box2";
} else if (sortedBoxes[0].equals("Gold")) {
return "The box containing the Gold is Box1";
} else {
return "The box containing the Gold is Box3";
}
}
}


Loading