2 333
订阅者
无数据24 小时
-37 天
-2030 天
帖子存档
👩💻 Welcome to @CodesSnippet! 🔫
Join us for daily snippets of coding👩💻 knowledge! 💻
Here, you'll find 👀 bite-sized pieces of code, programming tips, and tricks to level up your coding skills! 💻
Stay updated on the latest trends in the tech world and engage with fellow coders 💗 in our vibrant community! 🌐💬
Let's crack the coding 👩💻 together and bring your projects to life!
⭐️👨💻
Lang : Python , Java, Javascript, c++ and many more.
#CodeSnippet
#ProgrammingFun
Jᴏɪɴ ᴜs :- @CodesSnippet
━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Free Study Resources everything join more ✅ https://t.me/addlist/c3QWwWR-Iw4xMDNl
Subscribe Our New channel for coding, designing, hacking and computer related everything 😁
👉✅ https://youtube.com/@CODEBOMBB
━━━━━━━━━━━━━━━━━━━━━━━━━━━━
If you want learn js for website development 👇join it
@react_next_js
For any problems in js site development feel free to ask questions 😊👇
@reactjs_nextjs_group
Solution:
import java.util.Scanner;
public class Pattern {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the value of n: ");
int n = scan.nextInt();
for (int i = 1 ; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
System.out.print("1 ");
}
for(int k = 1; k <= i; k++){
System.out.print(i + " ");
}
System.out.println();
}
}
}Explanation:
str = str.replaceAll("\\s", "") : This line replaces all whitespace characters in the string
str with an empty string, effectively removing them. The \\s is a regular expression pattern that matches any whitespace character, such as spaces, tabs, or newlines. The double backslash \\ is necessary because \ is an escape character in Java strings, so to represent a single backslash in a regular expression, you need to escape it with another backslash.#TaskAnswer
public class TaskAnswer {
public static void main(String[] args) {
String str = "I am learning Java object oriented programming";
str = str.replaceAll("\\s", "");
System.out.println(str);
}
}
Output:
Iamlearningobjectorientedprogramming
Write code on task's comment, which code will be best that code should be posted here with those name
After 8pm today
#Taskforyou
Write a Java program that remove the extra spaces from the following string:
' I am learning Java object oriented programming '
Java all Codes listed see pin message 👆
Or you can search any keyword
Example: "function" to see function related codes
Create compiler bot in mobile
Run any language codes
In hindi:
Ab laptop ko kar do Tata bye bye gya 😂
https://youtu.be/352o8B9IikI?si=OSrhBU0mcFEkqILA
Remaining Topics like Inheritance, Polymorphism, Hash Map, Wrapper Classes, Regex, Threads, Lamda will be added soon
Output:
Deleted the file: test.txt
Failed to delete the folder.
Output of 14 Syntax:File Delete and folder
//14 Syntax:File Delete and folder
import java.io.File;
public class DeleteFile {
public static void main(String[] args) {
try{
File DObj = new File("Location Of File");
if (DObj.delete()) {
System.out.println("Deleted the file: " + DObj.getName());
} else {
System.out.println("Failed to delete the file.");
}
}catch(Exception e){
System.out.println("Failed to delete the folder.");
}
finally{
File DFObj = new File("Location of Folder");
if (DFObj.delete()) {
System.out.println("Deleted the folder: " + DFObj.getName());
} else {
System.out.println("Failed to delete the folder.");
}
}
}
}
//Note This code can only run in Your PCOutput:
File name: test.txt
Absolute path: /home/runner/compilers/./test/test.txt
Writeable: true
Readable true
File size in bytes 18
What am I writting
Output of 14 Syntax:File Read / Info
//14 Syntax:File Read / Info
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ReadFile {
public static void main(String[] args) {
File Obj = new File("Location of text File");
if (Obj.exists()) {
System.out.println("File name: " + Obj.getName());
System.out.println("Absolute path: " + Obj.getAbsolutePath());
System.out.println("Writeable: " + Obj.canWrite());
System.out.println("Readable " + Obj.canRead());
System.out.println("File size in bytes " + Obj.length());
}
else {
System.out.println("The file does not exist.");
}
try {
File ObjR = new File("Location of text file");
Scanner MReader = new Scanner(ObjR);
while (MReader.hasNextLine()) {
String data = MReader.nextLine();
System.out.println(data);
}
MReader.close();
}catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
//Note This code can only run in Your PCOutput:
File created: test.txt
Successfully wrote to the file
Output of 14 Syntax:File Create / write
//14 Syntax:File Create / write
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class CreateFile {
public static void main(String[] args) {
try {
File Obj = new File("Give Location where to create File");
if (Obj.createNewFile()) {
System.out.println("File created: " + Obj.getName());
FileWriter MWriter = new FileWriter("give Location of file which to write");
MWriter.write("What am I writting");
MWriter.close();
System.out.println("Successfully wrote to the file.");
} else {
System.out.println("File already exists.");
}
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
//Note This code can only run in Your PCException in thread "main" java.lang.ArithmeticException: Access denied at Main.main(Main.java:3)
Output of 13 Syntax:Exception handling 03
