[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / asp / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / qst / sci / soc / sp / tg / toy / trv / tv / vp / wsg / wsr / x] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/sci/ - Science & Math

[Advertise on 4chan]

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • Use with [math] tags for inline and [eqn] tags for block equations.
  • Right-click equations to view the source.
  • There are 17 posters in this thread.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


Self-serve ads are available again! Check out our new advertising page here.


[Advertise on 4chan]


File: Capture.png (19 KB, 491x480)
19 KB
19 KB PNG
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++;
}
}
}

}
>>
>>12579364
fuck you, you gave my computer covid
>>
>>12579364
What does this code do mr Durga sir?
>>
>>12579364
People like this are writing unlicensed autopilot software.
>>
File: MyProgram.png (34 KB, 692x938)
34 KB
34 KB PNG
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);
}

}
>>
>>12579511
Very nice. I think it looks pretty cool!

Takes a while to compile though for large arguments
>>
>>12579364
>import java.lang.*;
Kill yourself
>>
>>12579579
Apparently 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
>>
>>12579364
This has to be the most disgusting waste of processor cycles I have seen in a good while.
>>
>>12579364
Print 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]}
}
>>
File: Jshit.jpg (221 KB, 1024x768)
221 KB
221 KB JPG
>>12579584
>using java
>ever
You don't belong here
>>
>>12579364
>import java.lang
Stopped reading right there
>>
poo here
vart 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]
>>
>>12580885
Yeah, 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: >>12580929

You: >>12579364
>>
Reuse your string buffer
use a for loop
don't use *, name each import
>>
>>12580974
This. 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
>>
>>12581417
He shits on the street for a living, of course he doesn't even know what int means.
>>
>>12579584
All 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.

>>12581416
is 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 expensive
Really makes you think.
>>
>>12581500
If 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.
>>
>>12581570
Performance stayed the same when I benchmarked it.
>>
>>12581412
Brainlet question but how exactly do you reuse the buffer
>>
File: right.png (4 KB, 340x225)
4 KB
4 KB PNG
>>12581616
You'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.
>>
>>12581616
thought this board was for smart people
>>
>>12582912
No
>>
>>12582912
OP is cs monkey





Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.