Search:

Type: Posts; User: Dragonfly11

Page 1 of 2 1 2

Search: Search took 0.07 seconds.

  1. Replies
    63
    Views
    4,376

    Re: Help with calculator

    Okay I see, I feel like I've done that (or at least tried...) but made a really bad code for it....I did manage to fix my problem with a isLetter statement. The problem I have now is that it prints...
  2. Replies
    63
    Views
    4,376

    Re: Help with calculator

    I see but I don't know how....and I don't have much time left on this assignment I have to deliver it tomorrow.
  3. Replies
    63
    Views
    4,376

    Re: Help with calculator

    you mean these?
    package com.company;

    import javax.swing.*;

    public class Main {

    public static void main(String[] args) {

    sorry for not including them
  4. Replies
    63
    Views
    4,376

    Re: Help with calculator

    String tal1 = "";
    String tal2 = "";

    String s = JOptionPane.showInputDialog("Skriv in tal");


    if (s.isEmpty()) {
    JOptionPane.showMessageDialog(null, "Får...
  5. Replies
    63
    Views
    4,376

    Re: Help with calculator

    No it doesn't work, I try doing it with a for loop with isdigit in it
    for (int i = 0; i <s.length() ; i++) {
    char a4 = s.charAt(i);
    if (!Character.isDigit(a4)) {
    ...
  6. Replies
    63
    Views
    4,376

    Re: Help with calculator

    okay thank you like this?
    returnValue = TheClassName.theMethodName(tal1);
  7. Replies
    63
    Views
    4,376

    Re: Help with calculator

    okay we've been told to use isdigit but I don't know how to use it...
  8. Replies
    63
    Views
    4,376

    Re: Help with calculator

    okay I solved it like this

    int count=0;

    for ( int i=0; i<s.length(); i++) {
    if (s.charAt(i) == '*' || s.charAt(i) == '/' || s.charAt(i) == '+' || s.charAt(i) == '-') {

    ...
  9. Replies
    63
    Views
    4,376

    Re: Help with calculator

    Okay I have solved all of it and I don't have much time on this assignment. How do I make error message if there is a letter in the input?
  10. Replies
    63
    Views
    4,376

    Re: Help with calculator

    okay something like this?


    for (i=0; i<s.length(); i++)
    if (s.charAt(i) == '')
  11. Replies
    63
    Views
    4,376

    Re: Help with calculator

    No I haven't learn about it yet and I'm not sure if my teacher will allow it but I'll ask him. So I can't use if statement or a for loop?
  12. Replies
    63
    Views
    4,376

    Re: Help with calculator

    Yes it worked!! I only need now to make error messages when you try to /0 and if you try to use more than to numbers. So when you type in for example 2+2-1, you're supposed to get an error message....
  13. Replies
    63
    Views
    4,376

    Re: Help with calculator

    like this?
    int result = (num4 + num5);
    System.out.println(result);
  14. Replies
    63
    Views
    4,376

    Re: Help with calculator

    okay what is assignment statement?
  15. Replies
    63
    Views
    4,376

    Re: Help with calculator

    I tried making them into one string and convert it to int to print out but then it prints out 34144



    String result = num1 + num2;
    int num4 = Integer.parseInt(result);

    ...
  16. Replies
    63
    Views
    4,376

    Re: Help with calculator

    The result of what 341+44 is
  17. Replies
    63
    Views
    4,376

    Re: Help with calculator

    Okay


    int num4 = Integer.parseInt(num2);
    int num5 = Integer.parseInt(num1);

    What am I going to put in my print code?
  18. Replies
    63
    Views
    4,376

    Re: Help with calculator

    I understand I changed my string to 341+44 and tecken+1 prints out 44 and 0, tecken prints out 321
  19. Replies
    63
    Views
    4,376

    Re: Help with calculator

    Yes thank you! (tecken+1) only prints our the last number now.
  20. Replies
    63
    Views
    4,376

    Re: Help with calculator

    String num2 = num.substring(tecken);
    String num1 = num.substring(0, tecken);

    Okay! So the 0,tecken prints out the first number and the one with tecken prints out + and the second number
  21. Replies
    63
    Views
    4,376

    Re: Help with calculator

    String num2 = num.substring(tecken, 2);
    String num1 = num.substring(0, tecken);

    it only print out 1
  22. Replies
    63
    Views
    4,376

    Re: Help with calculator

    like this?


    int index = num.indexOf("num");
    String num2 = num.substring(0, index);
    String num1 = num.substring(index);
  23. Replies
    63
    Views
    4,376

    Re: Help with calculator

    Okay like this?


    String num1 = num.substring(0, 2);
    String num2 = num.substring(0, 1);
  24. Replies
    63
    Views
    4,376

    Re: Help with calculator

    Okay I've been trying to do that with "+" for example with an index of code, but I don't understand the result when I run the code in the terminal I just get 1.



    String num = "1+2";
    int tecken...
  25. Replies
    63
    Views
    4,376

    Re: Help with calculator

    My code is supposed to accept two numbers and able to count in +, -, * and / (any number(any of these: +, *, -, /) any number)
Results 1 to 25 of 32
Page 1 of 2 1 2