// #1 Your First Program
class HelloWorld {
public static void main(String[] args){
System.out.println("Hello, World!");
}
}
class HelloWorld {
public static void main(String[] args){
System.out.println("Hello, World!");
}
}
// #2 For Adding 2 numbers
public class MyClass {
public static void main(String args[]) {
int x=10;
int y=25;
int z=x+y;
System.out.println("Sum of x+y = " + z);
}
}
public class MyClass {
public static void main(String args[]) {
int x=10;
int y=25;
int z=x+y;
System.out.println("Sum of x+y = " + z);
}
}
👍3
// Airthmetic Operations in Java
public class MyClass {
public static void main(String args[]) {
// declaring variables
int add, sub, div, mul, r;
// Declaring two varables
int x=4;
int y=2;
// performing Operations
add = x+y; // Addition
sub = x-y; // Subtraction
div = x/y; // Division
mul = x+y; // Multiply
r= x%y; // re m inder
// Showing results
System.out.println("4 + 2 = "+ add);
System.out.println("4 - 2 = "+ sub);
System.out.println("4 * 2 = "+ mul);
System.out.println("4 / 2 = "+ div);
System.out.println("4 % 2 = "+ r);
}
}
// in this i introduced operators in java
// code by @Java_Codes_Pro
// buttons by @IOChannel_Bot
// Compiler @Compiler0bot
public class MyClass {
public static void main(String args[]) {
// declaring variables
int add, sub, div, mul, r;
// Declaring two varables
int x=4;
int y=2;
// performing Operations
add = x+y; // Addition
sub = x-y; // Subtraction
div = x/y; // Division
mul = x+y; // Multiply
r= x%y; // re m inder
// Showing results
System.out.println("4 + 2 = "+ add);
System.out.println("4 - 2 = "+ sub);
System.out.println("4 * 2 = "+ mul);
System.out.println("4 / 2 = "+ div);
System.out.println("4 % 2 = "+ r);
}
}
// in this i introduced operators in java
// code by @Java_Codes_Pro
// buttons by @IOChannel_Bot
// Compiler @Compiler0bot
👍2❤1
public class NumberTrianglePattern {
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " ");
}
System.out.println();
}
}
} // @Java_Codes_Pro
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " ");
}
System.out.println();
}
}
} // @Java_Codes_Pro
👍1
public class StarPyramidPattern {
public static void main(String[] args) {
int rows = 5;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < rows - i - 1; j++) {
System.out.print(" ");
}
for (int j = 0; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
}
}
// @Java_Codes_Pro
public static void main(String[] args) {
int rows = 5;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < rows - i - 1; j++) {
System.out.print(" ");
}
for (int j = 0; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
}
}
// @Java_Codes_Pro
👍2
public class DiamondPattern {
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = rows - 1; i >= 1; i--) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
// @Java_Codes_pro
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = rows - 1; i >= 1; i--) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
// @Java_Codes_pro
👍1
All Codes
@C_Code5
@CPP_Coding
@Python_Codes_Pro
@Java_Codes_Pro
@jsCode0
Diffrent free Compiler bots
✅ For group @CodeCompiler_Bot
✅ For channel @IOChannel_bot
✅ For Channel Cmpl @Compiler0bot
✅ For inline @cmpbbot
info in @LogicBots
Discussion
@bca_mca_btech
@C_Code5
@CPP_Coding
@Python_Codes_Pro
@Java_Codes_Pro
@jsCode0
Diffrent free Compiler bots
✅ For group @CodeCompiler_Bot
✅ For channel @IOChannel_bot
✅ For Channel Cmpl @Compiler0bot
✅ For inline @cmpbbot
info in @LogicBots
Discussion
@bca_mca_btech
// java string functions part 1
public class StringFunctionsProgram1 {
public static void main(String[] args) {
// STRING FUNCTIONS - PROGRAM 1
// 1. Length of the String
String str = "Hello, World!";
int length = str.length();
System.out.println("Length of the String: " + length);
// 2. Concatenation of Strings
String newStr = str.concat(" Welcome");
System.out.println("Concatenated String: " + newStr);
// 3. Extracting a Substring
String subStr = str.substring(7);
System.out.println("Substring: " + subStr);
// 4. Converting to Uppercase
String upperStr = str.toUpperCase();
System.out.println("Uppercase String: " + upperStr);
// 5. Converting to Lowercase
String lowerStr = str.toLowerCase();
System.out.println("Lowercase String: " + lowerStr);
// 6. Checking if a String starts with a specific prefix
boolean startsWith = str.startsWith("Hello");
System.out.println("Starts with 'Hello': " + startsWith);
// 7. Checking if a String ends with a specific suffix
boolean endsWith = str.endsWith("!");
System.out.println("Ends with '!': " + endsWith);
// 8. Finding the index of a specific character
int index = str.indexOf("o");
System.out.println("Index of 'o': " + index);
// 9. Replacing characters in a String
String replacedStr = str.replace("o", "x");
System.out.println("Replaced String: " + replacedStr);
// 10. Checking if a String contains a specific sequence of characters
boolean contains = str.contains("World");
System.out.println("Contains 'World': " + contains);
}
}
public class StringFunctionsProgram1 {
public static void main(String[] args) {
// STRING FUNCTIONS - PROGRAM 1
// 1. Length of the String
String str = "Hello, World!";
int length = str.length();
System.out.println("Length of the String: " + length);
// 2. Concatenation of Strings
String newStr = str.concat(" Welcome");
System.out.println("Concatenated String: " + newStr);
// 3. Extracting a Substring
String subStr = str.substring(7);
System.out.println("Substring: " + subStr);
// 4. Converting to Uppercase
String upperStr = str.toUpperCase();
System.out.println("Uppercase String: " + upperStr);
// 5. Converting to Lowercase
String lowerStr = str.toLowerCase();
System.out.println("Lowercase String: " + lowerStr);
// 6. Checking if a String starts with a specific prefix
boolean startsWith = str.startsWith("Hello");
System.out.println("Starts with 'Hello': " + startsWith);
// 7. Checking if a String ends with a specific suffix
boolean endsWith = str.endsWith("!");
System.out.println("Ends with '!': " + endsWith);
// 8. Finding the index of a specific character
int index = str.indexOf("o");
System.out.println("Index of 'o': " + index);
// 9. Replacing characters in a String
String replacedStr = str.replace("o", "x");
System.out.println("Replaced String: " + replacedStr);
// 10. Checking if a String contains a specific sequence of characters
boolean contains = str.contains("World");
System.out.println("Contains 'World': " + contains);
}
}
// java string functions part 2
public class StringFunctionsProgram2 {
public static void main(String[] args) {
// STRING FUNCTIONS - PROGRAM 2
// 1. Trimming leading and trailing whitespace
String str1 = " Hello, World! ";
String trimmedStr = str1.trim();
System.out.println("Trimmed String: " + trimmedStr);
// 2. Splitting a String into an array of substrings
String[] splitStr = str1.split(",");
System.out.println("Split Strings:");
for (String split : splitStr) {
System.out.println(split.trim());
}
// 3. Checking if two Strings are equal
String str2 = "Hello";
boolean isEqual = str1.equals(str2);
System.out.println("Strings are equal: " + isEqual);
// 4. Getting the character at a specific index
char charAt = str2.charAt(1);
System.out.println("Character at index 1: " + charAt);
// 5. Checking if a String is empty
boolean isEmpty = str2.isEmpty();
System.out.println("Is empty: " + isEmpty);
// 6. Removing leading and trailing characters
String removedStr = str1.strip();
System.out.println("Removed String: " + removedStr);
// 7. Reversing a String
StringBuilder reversedStr = new StringBuilder(str1).reverse();
System.out.println("Reversed String: " + reversedStr);
// 8. Checking if a String matches a regular expression
boolean matchesRegex = str1.matches("Hello.*");
System.out.println("Matches regular expression 'Hello.*': " + matchesRegex);
// 9. Formatting a String
String formattedStr = String.format("Price: $%.2f", 10.5);
System.out.println("Formatted String: " + formattedStr);
// 10. Comparing two Strings lexicographically
int comparison = str1.compareTo("Goodbye");
System.out.println("Comparison result: " + comparison);
}
}
// See t.me/Java_Codes_Pro/52
public class StringFunctionsProgram2 {
public static void main(String[] args) {
// STRING FUNCTIONS - PROGRAM 2
// 1. Trimming leading and trailing whitespace
String str1 = " Hello, World! ";
String trimmedStr = str1.trim();
System.out.println("Trimmed String: " + trimmedStr);
// 2. Splitting a String into an array of substrings
String[] splitStr = str1.split(",");
System.out.println("Split Strings:");
for (String split : splitStr) {
System.out.println(split.trim());
}
// 3. Checking if two Strings are equal
String str2 = "Hello";
boolean isEqual = str1.equals(str2);
System.out.println("Strings are equal: " + isEqual);
// 4. Getting the character at a specific index
char charAt = str2.charAt(1);
System.out.println("Character at index 1: " + charAt);
// 5. Checking if a String is empty
boolean isEmpty = str2.isEmpty();
System.out.println("Is empty: " + isEmpty);
// 6. Removing leading and trailing characters
String removedStr = str1.strip();
System.out.println("Removed String: " + removedStr);
// 7. Reversing a String
StringBuilder reversedStr = new StringBuilder(str1).reverse();
System.out.println("Reversed String: " + reversedStr);
// 8. Checking if a String matches a regular expression
boolean matchesRegex = str1.matches("Hello.*");
System.out.println("Matches regular expression 'Hello.*': " + matchesRegex);
// 9. Formatting a String
String formattedStr = String.format("Price: $%.2f", 10.5);
System.out.println("Formatted String: " + formattedStr);
// 10. Comparing two Strings lexicographically
int comparison = str1.compareTo("Goodbye");
System.out.println("Comparison result: " + comparison);
}
}
// See t.me/Java_Codes_Pro/52
👍3
// java basic threads example
public class MultithreadingExample {
public static void main(String[] args) {
// Creating and starting two threads
Thread thread1 = new MyThread("Thread 1");
Thread thread2 = new MyThread("Thread 2");
thread1.start();
thread2.start();
}
}
class MyThread extends Thread {
private String threadName;
public MyThread(String name) {
threadName = name;
}
public void run() {
for (int i = 1; i <= 5; i++) {
System.out.println(threadName + " - Count: " + i);
try {
Thread.sleep(1000); // Pause for 1 second
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} // @Java_Codes_Pro
public class MultithreadingExample {
public static void main(String[] args) {
// Creating and starting two threads
Thread thread1 = new MyThread("Thread 1");
Thread thread2 = new MyThread("Thread 2");
thread1.start();
thread2.start();
}
}
class MyThread extends Thread {
private String threadName;
public MyThread(String name) {
threadName = name;
}
public void run() {
for (int i = 1; i <= 5; i++) {
System.out.println(threadName + " - Count: " + i);
try {
Thread.sleep(1000); // Pause for 1 second
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} // @Java_Codes_Pro
👍2
// Arrays in Java
public class MyClass {
public static void main(String args[]) {
int arr[] = {2, 3, 6};
//Array declaration and initialization
System.out.println(arr[0]);
//Showing Array First element
}
} // @Java_Codes_pro
public class MyClass {
public static void main(String args[]) {
int arr[] = {2, 3, 6};
//Array declaration and initialization
System.out.println(arr[0]);
//Showing Array First element
}
} // @Java_Codes_pro
// fetch song lyrics from url
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.PrintWriter;
public class GetSongLyrics {
public static void main(String[] args) {
String url = "https://song.panditsiddharth.repl.co/lyrics?song=ram+siya+ram";
try {
URL requestUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
connection.setRequestMethod("GET");
int statusCode = connection.getResponseCode();
BufferedReader reader;
if (statusCode == HttpURLConnection.HTTP_OK) {
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
} else {
reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
}
PrintWriter writer = new PrintWriter(System.out);
String line;
while ((line = reader.readLine()) != null) {
writer.println(line);
}
reader.close();
writer.flush();
connection.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
} // @Java_Codes_Pro
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.PrintWriter;
public class GetSongLyrics {
public static void main(String[] args) {
String url = "https://song.panditsiddharth.repl.co/lyrics?song=ram+siya+ram";
try {
URL requestUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
connection.setRequestMethod("GET");
int statusCode = connection.getResponseCode();
BufferedReader reader;
if (statusCode == HttpURLConnection.HTTP_OK) {
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
} else {
reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
}
PrintWriter writer = new PrintWriter(System.out);
String line;
while ((line = reader.readLine()) != null) {
writer.println(line);
}
reader.close();
writer.flush();
connection.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
} // @Java_Codes_Pro
👍1
// Curried function in java (nested functions)
import java.util.function.Function;
public class CurryingExample {
public static void main(String[] args) {
Function<Integer, Function<Integer, Integer>> multiply = a -> b -> a * b;
// Curried function can be used with partial application
Function<Integer, Integer> multiplyByTwo = multiply.apply(2);
System.out.println(multiplyByTwo.apply(4)); // Output: 8
// Or it can be invoked with all arguments at once
System.out.println(multiply.apply(3).apply(5)); // Output: 15
}
} // @Java_Codes_Pro
import java.util.function.Function;
public class CurryingExample {
public static void main(String[] args) {
Function<Integer, Function<Integer, Integer>> multiply = a -> b -> a * b;
// Curried function can be used with partial application
Function<Integer, Integer> multiplyByTwo = multiply.apply(2);
System.out.println(multiplyByTwo.apply(4)); // Output: 8
// Or it can be invoked with all arguments at once
System.out.println(multiply.apply(3).apply(5)); // Output: 15
}
} // @Java_Codes_Pro
👏1
Strings functions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
@Java_Codes_Pro #share #support
1.
length(): Returns the length of a string.2.
toUpperCase(): Converts a string to uppercase.3.
toLowerCase(): Converts a string to lowercase.4.
charAt(index): Returns the character at the specified index of a string.5.
indexOf(searchValue): Returns the index of the first occurrence of a specified value in a string.6.
lastIndexOf(searchValue): Returns the index of the last occurrence of a specified value in a string.7.
substring(startIndex): Returns a substring from a string, starting from the specified index to the end of the string.8.
substring(startIndex, endIndex): Returns a substring from a string, between the specified start and end indexes.9.
replace(oldValue, newValue): Replaces occurrences of a specified value with another value in a string.10.
split(separator): Splits a string into an array of substrings based on the specified separator.11.
trim(): Removes leading and trailing whitespace from a string.12.
startsWith(prefix): Returns true if a string starts with the specified prefix; otherwise, returns false.13.
endsWith(suffix): Returns true if a string ends with the specified suffix; otherwise, returns false.14.
contains(searchValue): Returns true if a string contains the specified value; otherwise, returns false.15.
equals(anotherString): Compares two strings for equality.16.
equalsIgnoreCase(anotherString): Compares two strings for equality, ignoring case differences.@Java_Codes_Pro #share #support
👍7🥰1
public class Main {
public static void main(String[] args) {
String message = new String(new int[] {32, 72, 97, 112, 112, 121, 32, 73, 110, 100, 101, 112, 101, 110, 100, 101, 110, 99, 101, 32, 100, 97, 121, 33}, 0, 24);
System.out.println(message);
}
}
// @java_Codes_pro
public static void main(String[] args) {
String message = new String(new int[] {32, 72, 97, 112, 112, 121, 32, 73, 110, 100, 101, 112, 101, 110, 100, 101, 110, 99, 101, 32, 100, 97, 121, 33}, 0, 24);
System.out.println(message);
}
}
// @java_Codes_pro
Java Codes Basic to Advance pinned «Strings functions 1. length(): Returns the length of a string. 2. toUpperCase(): Converts a string to uppercase. 3. toLowerCase(): Converts a string to lowercase. 4. charAt(index): Returns the character at the specified index of a string. 5. indexOf(searchValue):…»
Notes 📝 :
Telegram.me/BCA_Sem1_Notes
Telegram.me/BCA_Sem2_Notes
Telegram.me/BCA_Sem3_Notes
Telegram.me/BCA_Sem4_Notes
Telegram.me/BCA_Sem5_Notes
Telegram.me/BCA_Sem6_Notes
Code practice Channels:
Telegram.me/C_Codes_pro
Telegram.me/CPP_Codes_pro
Telegram.me/Python_Codes_pro
Telegram.me/Java_Codes_Pro
Telegram.me/Nodejs_Codes_Pro
Info channel:
Telegram.me/Btech_bca_mca
Discussion groups:
Telegram.me/bca_mca_btech
Telegram.me/bca_group_ignou
Learn coding:
Youtube.com/IgnouStudyCenter
Telegram.me/BCA_Sem1_Notes
Telegram.me/BCA_Sem2_Notes
Telegram.me/BCA_Sem3_Notes
Telegram.me/BCA_Sem4_Notes
Telegram.me/BCA_Sem5_Notes
Telegram.me/BCA_Sem6_Notes
Code practice Channels:
Telegram.me/C_Codes_pro
Telegram.me/CPP_Codes_pro
Telegram.me/Python_Codes_pro
Telegram.me/Java_Codes_Pro
Telegram.me/Nodejs_Codes_Pro
Info channel:
Telegram.me/Btech_bca_mca
Discussion groups:
Telegram.me/bca_mca_btech
Telegram.me/bca_group_ignou
Learn coding:
Youtube.com/IgnouStudyCenter
👍2