For instance, it converts C to F. It converts F to 0 C. My conversion formulas are right. Can anyone give me some clues? I tried declaring the floats in the class outside the main, but it didn't help. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 7 months ago. Active 8 years, 7 months ago. Viewed 24k times. Improve this question. Java Abstract Class.
Abstract Method In Java. Interfaces, Packages and Access Control. Java Interface. Java Package. How To Compile Classes in Package. Access Modifiers In Java. Static Keyword In Java. Singleton Design Pattern In Java. Object Oriented Concepts - Revisited. Abstraction in Java. Polymorphism In Java. Encapsulation In Java.
Inheritance In Java. Why Java Throws Exceptions. Try Catch Block In Java. User Defined Exception In Java. Difference Between Error and Exception in Java. Multithreaded Programming. Thread Concept In Java. The Java Thread Model. Creation Of Threads In Java. Java Synchronized Blocks. Java Thread Group. Java Generics. A Simple Generics Example. Generic Interface In Java. Java Type Erasure. Java String. Special String Operations. Literals In Java. Java String concatenation - concat Method In Java.
Character Extraction. String Comparison. Java regionMatches Method - String Comparison. Java compareTo method.
Modifying a String. Java String substring method - substring In Java. Additional String Methods in Java. Java StringBuffer. Java StringBuffer length And capacity Methods.
Java append Method In StringBuffer. Java substring. StringBuilder Class In Java. Conclusion Of Strings In Java. Exploring java. Primitive Type Wrappers. Java Number Class.
Converting Numbers to and from Strings In Java. Java Character Class. Java Boolean Class. Java Void Class. Java Process Class. Java Runtime Class - java. Java ProcessBuilder. System Class arraycopy Method In Java. Java Environment Properties. Java ClassLoader. Java Math Class - java. Java Package Class. Java Enumeration. Java Comparable Interface with Example. Conclusion Exploring java. Collections Framework. Java Collections Overview. Collection Interface.
Java List Interface. Set Interface In Java. Java SortedSet Interface. Java NavigableSet Interface. Collection Classes. Java ArrayList. Java LinkedList. HashSet Class In Java. Java LinkedHashSet. Java ArrayDeque Class. Java EnumSet.
Java Iterator. List Iterator In Java. Map Interfaces. Java SortedMap Interface. Java NavigableMap. Java Map. Entry Interface.
Map Classes. But you're presenting your code here to get advice how to improve your programming skills, so here are a few remarks. Take them as a hint where to go from here, as soon as you feel ready for the "next level". Your main method contains both aspects in one piece of code, even within the same line e. Make it a habit to separate tasks that can be named individually into methods of their own:.
With separate methods, it will be easier to later change your program to e. Your current program always forces the user to do exactly one C-to-F and then one F-to-C conversion. This will rarely both be needed at the same time. I'd either ask the user at the beginning for the conversion he wants, or make it two different programs. By the way, doing so will be easier if the different tasks have been separated. Combine variable declaration and value assignment.
You wrote double fahrenheit, celsius; and later e. This way, when reading your program maybe half a year later , you immediately see at the same place that celsius is a double number coming from some input. Using two separate characters does the job in a more robust way. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more.
0コメント