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:
Anonymous2009-02-18 0:15
No singletons or factories.
Your teacher is going to fail you.
Name:
Anonymous2009-02-18 0:25
>No singletons or factories.
yes singletons or factories.
fix'd
Name:
Anonymous2009-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";
}
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.
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.
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) {
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);
}
}
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.
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.
>>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:
Anonymous2009-02-19 15:22
3. REGEX EXPRESSIONS
The full expansion is REGEX REGULAR EXPREGEX REGEXPREGULAR EXPRESSIONS
Name:
Anonymous2009-02-19 17:14
>>37
all of those things are the complete opposite of ENTERPRISE QUALITY.
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
Name:
Anonymous2009-02-19 20:56
(defn c-to-f [temp]
(+ 32 (* 1.8 temp)))
(defn f-to-c [temp]
(/ (- temp 32) 1.8))
(defn main []
(println "Input temperature in C or F: ")
(let [temp
(Double/parseDouble (read-line))]
(printf "%.2f F\n" (c-to-f temp))
(printf "%.2f C\n" (f-to-c temp))))
Name:
Anonymous2009-02-19 21:33
>>41
That doesn't convert based on the input scale.
Name:
Anonymous2009-02-19 21:37
>>42 >>1 actually only wanted Celsius to Fahrenheit.
#!/usr/bin/env ruby
c={'C'=>lambda{|x| 32+1.8*x },'F'=>lambda{|x| (x-32)/1.8 }}
(print "Input temperature in C or F: ";t=gets) until t=~/^(\d+)([CF])$/;
print "Converted is: ",c[$2].call($1.to_i),"\n";
Name:
Anonymous2009-02-20 17:11
Too many outputs without units, hope none of you ever work on actual physics projects.
Name:
Anonymous2009-02-20 18:53
I also need a job.
I interviewed for a c++ role but didnt get it. It made realize that im not c++ fan boi enough for enterprise places.
I also interviewed for a systems role in c. that went much better. but they havent called me.
>>53
Did you show them your EXPERTBBCODE portfolio?
Name:
Anonymous2009-02-21 2:11
>>49
Second year computer science students don't get jobs.
Name:
Penis Head2009-02-21 3:20
I'm a noob programmer and this was easy.
public class degCtoF
{
public static void main(String[] args)
{
in new = BufferedReader(new InputStreamReader System(in.String));
while(true)
}
try
{
System.out.printf("/nDegrees Celcius:/n");
int C = integer.parseInt(in.readLine());
break;
}
catch (Exception e) System.out.printf("/nnot a valid number/n");
}
System.out.printf("Farenheit = %.2f",C*1.8+32);
}
}
Name:
Anonymous2009-02-21 3:25
hey OP, submit this. It works better than any of the programs above:
void main(){while(1);}
Name:
Anonymous2009-03-06 13:25
This day THE EXPERTS took revenge on The Abelson carving parentheses into his mouth and proceeded to give me the best blow job I have a pretty bad worse than Python could possibly exist but somehow php.