logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

Jak wprowadzić trzy dane do kalkulatora w Java?

mlodyprzemas 25 Kwi 2005 21:23 1322 3
REKLAMA
  • #1 1436994
    mlodyprzemas
    Poziom 10  
    Posty: 37
    Kiedyś już miałem taki problem. Mianowicie mam coś w rodzaju kalkulatora ale potrzebuje trzech wprowadzonych danych. Czy ktoś mugłby mi powiedzieć jak to zrobić.
    Proszę o pomoc.
  • REKLAMA
  • #2 1437427
    ziel_inf
    Poziom 15  
    Posty: 192
    Pomógł: 2
    Ocena: 11
    jak ten kalkulator ma działać: tryb graficzny? textowy? jakie działania mat. ? mam kilka projektów w jave tego typu ale który wrzucić :) ?
  • REKLAMA
  • #3 1438947
    mlodyprzemas
    Poziom 10  
    Posty: 37
    Nie nie. Chdzi mi o progam w trybie tekstowym tylko nie wiem jak wprowadzi trzy dane pokoleji. Czy wiesz jak to zrobić?
  • #4 1439094
    ziel_inf
    Poziom 15  
    Posty: 192
    Pomógł: 2
    Ocena: 11
    dane z konsoli do bufora do bufora 1, 2, 3.
    A w ogóle masz przykład na dwa - dodaj jeszcze trzecią zmienna i jet ok
    kompolowane pod linux. powinno pójśc i na windzie . jak chcesz dam plik. class na pw
    import java.io.*;
    
    public class Calculate {
    
        private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
        /**
         * Gets two numbers from user, adds them, and prints out the result.
         */
        void add() {
            float n1 = getNumber();
            float n2 = getNumber();
            float sum = n1 + n2;
            putNumber(sum);
        }
        
        /**
         * Outputs a number to the screen.
         */
        void putNumber(float result) {
            System.out.println(result);
        }
        
        /**
         * Asks the user to input a number and returns it.
         */
        float getNumber() {
            while (true) {
                String s = "";
                try {
                    System.out.print("Enter a number: ");
                    s = in.readLine();
                    return Float.parseFloat(s);
                } catch (NumberFormatException e) {
                    System.err.println("'" + s
                            + "' is not a valid decimal number.");
                } catch (IOException e) {
                    System.err.println("Could not read a number from user input!");
                }
                System.err.println("Try again.");
            }
        }
    
        /**
         * Entry point for the program.  Simply calls add method.
         */
        public static void main(String[] args) {
    	Calculate cal = new Calculate();
    	cal.add();
        }
    }
    
REKLAMA