import java.lang.*;import java.io.*;import java.util.*;public class MyProgram{public static void main(String[] args){int n = 100000;int k = 0;while (n<1000000){String str0 = String.valueOf(n);String str1 = str0.substring(0,3);String str2 = str0.substring(3);StringBuffer sbr = new StringBuffer(str2);sbr.reverse();String str3 = sbr.toString();if (str1.equals(str3)) {System.out.println(n);n++;}else {n++;}}}}
>>12579364fuck you, you gave my computer covid
>>12579364What does this code do mr Durga sir?
>>12579364People like this are writing unlicensed autopilot software.
import java.util.Scanner;public class MyProgram { public static void Tree(int segment, int height) { int x; int y; int z = 0; for (int i = 0; i < segment; i++) { x = 0; y = 0; for (int j = 0; j < height; j++) { for (int k = height + segment - j - z; k > 2; k--) { System.out.print(" "); } for (int l = 0; l < 1 + 2*x + 2*z; l++) { System.out.print("*"); } System.out.println(); x += 1; } z += 1; y += 1; } for (int m = 0; m < 2; m++) { for (int n = 2; n < height + z; n++) { System.out.print(" "); } System.out.println("*"); } for (int o = 5; o < height + z; o++) { System.out.print(" "); } if (height + segment > 6) { for (int p = 7; p > 0; p--) { System.out.print("*"); } } else { for (int q = 0; q < height + segment + 2; q++) { System.out.print("*"); } } } public static void main(String args[]) { Scanner scan = new Scanner(System.in); System.out.println("Enter the desired number of segments below"); int segment_input = scan.nextInt(); System.out.println("Enter the desired height of the segments below"); int height_input = scan.nextInt(); Tree(segment_input, height_input); }}
>>12579511Very nice. I think it looks pretty cool!Takes a while to compile though for large arguments
>>12579364>import java.lang.*;Kill yourself
>>12579579Apparently strings are "immutable objects" so you can't fucking reverse them without importing the lang library and using a String Buffer. don't blame me blame oracle
>>12579364This has to be the most disgusting waste of processor cycles I have seen in a good while.
>>12579364Print out all 6 digit numbers that are palindromes?#include <iostream>#include <iomanip>int main(){[math]~~[/math]for(int i = 100, j=001; i<1000; ++i){[math]~~~~[/math]std::cout << i << std::setfill ('0') << std::setw (3) << j << '\n';[math]~~~~[/math]if(j>=900){ [math]~~~~~~[/math]if(j>=990)[math]~~~~~~~~[/math]j-=989;[math]~~~~~~[/math]else[math]~~~~~~~~[/math]j-=890;[math]~~~~[/math]}[math]~~~~[/math]else[math]~~~~~~[/math]j+=100;[math]~~[/math]} }
>>12579584>using java>everYou don't belong here
>>12579364>import java.langStopped reading right there
poo herevart is doing wrong, sir?
This shit is so putrid, I think I might just start plumbing school
>>12579638>You don't belong here>/sci/Dude what? Java has been taught in all major unis for the past two decades in almost every CS/Math class
>>12579364[code]import java.lang.*;import java.io.*;import java.util.*;public class MyProgram{ public static String reverse(int n) { StringBuffer buf = new StringBuffer(String.valueOf(n)); buf.reverse(); return buf.toString(); } public static void main(String[] args) { for (int n = 100; n < 1000; n++) System.out.println(n + reverse(n)); }}[/code]
>>12580885Yeah, it's the brainlet language for CS kiddies. Intelligent majors learn matlab/python/C++.>>>/g/et out
The program she tells you not to worry about: >>12580929You: >>12579364
Reuse your string bufferuse a for loopdon't use *, name each import
>>12580974This. Java rots your brain into thinking using strings is a good idea. Literally a 2 line program in C++:for(int i=100; i<1000; ++i)std::cout << i*1001 + (i%10)*99 - 99*(i/100) << '\n';
>>12579364>int k = 0;For what?
import gf
>>12581417He shits on the street for a living, of course he doesn't even know what int means.
>>12579584All GC'd languages seem to have this in common, C# and Go to mention a few, with the reasoning that they're safer to work with and inherently thread safe. Your code is shit either way, you need 1(ONE) string buffer to populate with results which you then print at the end of looping.>>12581416is also shit because it prints the result every iteration.
>>12581481>you need 1(ONE) string buffer to populate with results which you then print at the end of looping.>print every iteration>performance is shit because of IO>append to a string every iteration>performance is shit because string manipulation is expensiveReally makes you think.
>>12581500If you need to think about it you're a tard, appending the result to a mutable string is several orders of magnitude faster than printing the result every iteration, especially so if you can preallocate a rather large string buffer beforehand.
>>12581570Performance stayed the same when I benchmarked it.
>>12581412Brainlet question but how exactly do you reuse the buffer
>>12581616You've done something wrong if that's the result. Writing to a buffer in memory vs invoking a system call that propagates the data to the console host & graphics subsystem for drawing text, what you're suggesting is simply not possible.
>>12581616thought this board was for smart people
>>12582912No
>>12582912OP is cs monkey