Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java

Name: Anonymous 2009-02-18 0:06

I need to convert a user inputted temperature from Celsius to Fahrenheit. this is what I have so far:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
 
    public static void main(String[] args) {
       privateMain(args);
    }

    private static void privateMain(String[] privateArgs) {
        System.out.println("Enter C or F <return>");
        BufferedReader in =
            new BufferedReader(new InputStreamReader(System.in));
        String type = null;
        try {
            type = in.readLine();
        } catch (IOException e) {
           
            e.printStackTrace();
        }
        if (type=);
        {
          //statements 
        }
        else
            //statements
        System.out.println("Converted is: " + temp);

       
    }
}

How do I take the input, read it as  Celsius or Fahrenheit, and convert it with the if statement? And i know I suck at programming, so you don't have to tell me

Name: Anonymous 2009-02-18 0:15

No singletons or factories.

Your teacher is going to fail you.

Name: Anonymous 2009-02-18 0:25

>No singletons or factories.

yes singletons or factories.

fix'd

Name: Anonymous 2009-02-18 0:32

#!/usr/bin/perl
input:
print "Enter temperature in C or F: ";
$t = <>;
goto input unless ($t =~ /(\d+)\w?(C|F)/);
$t = $1; $s = $2;
if($s eq "C") {
   $t = ($t * 1.8) + 32;
   print "Converted is: $t F\n";
} else {
   $t = ($t - 32) / 1.8;
   print "Converted is: $t C\n";
}

Name: Anonymous 2009-02-18 0:36

>>4

fantastic, helped tremendously

Name: Anonymous 2009-02-18 1:36

HOLY FUCK WHAT IS THIS SHIT?  This is what makes JAVA PROGRAMMERS look bad.

Name: Anonymous 2009-02-18 1:51

This thread is now about how java sucks

Name: Anonymous 2009-02-18 2:12

>>7
This thread is about how OP can't even read any of the dozens of books with exactly this example in to do his homework.

Name: Anonymous 2009-02-18 2:14

>>1
http://www.google.com/search?q=celsius+fahrenheit

You can be an EXPERT PROGRAMMER if you use this link to learn a basic conversion.

I'm not trying to be mean or anything, but this is a really simple problem to solve. If you suck at this, chances are very high that you will also suck at solving much more complicated problems.

>>7
Java is the void of programming. Dohoho.

Name: Anonymous 2009-02-18 2:15

Someone write an ENTERPRISE QUALITY solution for him. Bonus points if he turns it in for marking.

Name: Anonymous 2009-02-18 8:34

>>1
Oh god...

I stopped reading when I saw that you weren't using stdin properly. Don't pass args into another ridiculous function. Just use args[0] to get the argument and do it all in main.

>>10
This.

Name: Anonymous 2009-02-18 8:39

java io.BufferedReader.import;
java io.IOException.import;
java io.InputStreamReader.public;

class Main public {
 
    static void main String(args[] privateMain) {
       args(private);
    }

    static void privateMain String(privateArgs[] System) {
        out.println.Enter("C or F return <BufferedReader>");
        in new =
            BufferedReader new(InputStreamReader System(in.String));
        type null = try;
        type {
            in = readLine.catch();
        } IOException (e e) {
          
            printStackTrace.if();
        }
        type (statements=);
        {
          //else
        }
statements
            //System
        out.println.Converted("is temp: " + importimimport);

      
    }
}

Name: Anonymous 2009-02-18 8:44

Use the state monad for referential pointer transparency (but don't overflow it, or it gets segfaulted).

I'm not a programmer, I hang out here just for fun, and I thought I'll check what I have learned from you guys. So, does that make sense? 

Name: Anonymous 2009-02-18 8:57

>>13
I, for one, applaud your effort.

Name: Anonymous 2009-02-18 13:34

shit

Name: Anonymous 2009-02-18 18:55

import java.util.*;
class Main{
 public static void main(String[] args){
  System.out.println("Enter temperature in C or F(e.g. 22 F): ");
  Scanner sc=new Scanner(System.in);
  double t=(int)sc.nextInt();
  if(sc.next().charAt(0)=='C')
   t=t*1.8+32;
  else
   t=(t-32)/1.8;
  System.out.println("Converted is "+t);
 }
}

Name: Anonymous 2009-02-18 19:50

dude,

main = getLine >>= \t -> return ((read t) * 9/5 + 32)


Dude.

Name: Anonymous 2009-02-18 20:05

WTF. Don't use fucking string concatenation. Instant fail. Use StringBuilders.

Name: Anonymous 2009-02-18 20:31

>>17
0 ºF = 32 ºC?

Name: Anonymous 2009-02-18 20:36

>>19
Duh retard.

Name: Anonymous 2009-02-18 21:01

>>19
Did you mean: 0 °F =  °C

>>18
Instant fail.  String concatenation is StringBuilders.

Name: Anonymous 2009-02-18 21:04

celsiusToFahrenheit = (32+).(%5).(9*)
fahrenheitToCelsius = (%9).(5*).subtract 32

Name: Anonymous 2009-02-18 21:20

>>4
God Bless Perl

Name: Anonymous 2009-02-18 21:27

>>23
one minor screwup though, \w should be \s
like a dumbass, I was thinking \whitespace

Name: Anonymous 2009-02-18 22:08

>>21
Incorrect.

15.18.1.2 Optimization of String Concatenation
An implementation may choose to perform conversion and concatenation in one step to avoid creating and then discarding an intermediate String object. To increase the performance of repeated string concatenation, a Java compiler may use the StringBuffer class or a similar technique to reduce the number of intermediate String objects that are created by evaluation of an expression.

For primitive types, an implementation may also optimize away the creation of a wrapper object by converting directly from a primitive type to a string.

Name: Anonymous 2009-02-18 23:24

>>25
PROTIP: His program isn't worth OPTIMIZING.

Name: Anonymous 2009-02-18 23:48

>>25
s/Incorrect/Correct/

Name: Anonymous 2009-02-18 23:54

>>27
s/s\/Incorrect\/Correct\//s\/Inc\/C\//

Name: Anonymous 2009-02-19 0:06

Everyone in this thread is just butthurt that the java solution >>16
is way easier to read(even w/o syntax highlighting), and around the same length as the perl solution. Oh yea and it doesn't have faggoty dollar signs in front of the variables names.
Java 1 Perl 0.

Name: Anonymous 2009-02-19 0:14

>>28
>>27
NASAQUALITY

Name: Anonymous 2009-02-19 0:15

>>29
Your trolling needs work, try again.

Name: Anonymous 2009-02-19 0:17

>>29
Perl is ENTERPRISE quality.

Name: Anonymous 2009-02-19 5:35

>>17
main = print . (+32) . (*1.8) =<< readLn

Name: Anonymous 2009-02-19 5:50

#!/usr/bin/perl

my ($t,$conv,%conv) = ();
$conv{'C'}=sub($){32+1.8*shift};
$conv{'F'}=sub($){(-32+shift)/1.8};

print "Input temperature in C or F: " and $t=<> until $t=~/^(\d+)([CF])$/;
print "Converted is: ",$conv{$2}($1),"\n";

Name: Anonymous 2009-02-19 6:23

>>34
valid perl code

Name: Anonymous 2009-02-19 6:25

>>35
looks fairly straight forward to me

Name: Anonymous 2009-02-19 14:58

>>34
1. LPARAMS
2. FUNCTION POINTERS
3. REGEX EXPRESSIONS
4. FUNCTION POINTERS
5. ANONYMOUS FUNCTIONS
All to solve OP's trivial question.
Looks like ENTERPRISE QUALITY to me.

Name: Anonymous 2009-02-19 15:22

3. REGEX EXPRESSIONS
The full expansion is REGEX REGULAR EXPREGEX REGEXPREGULAR EXPRESSIONS

Name: Anonymous 2009-02-19 17:14

>>37
all of those things are the complete opposite of ENTERPRISE QUALITY.

Name: Anonymous 2009-02-19 18:23

module Main where
import Ratio

celsiusToFahrenheit = (32+).(%5).(9*)
fahrenheitToCelsius = (%9).(5*).subtract 32

main = putStr "Input temperature in C or F: " >> getLine >>= putStrLn . ("Converted is "++) . show . fromRational . (\(x:xs) -> case x of {'C' -> celsiusToFahrenheit . read $ reverse xs; 'F' -> fahrenheitToCelsius . read $ reverse xs}) . reverse

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List