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...
Type: Posts; User: Dragonfly11
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...
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.
you mean these?
package com.company;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
sorry for not including them
String tal1 = "";
String tal2 = "";
String s = JOptionPane.showInputDialog("Skriv in tal");
if (s.isEmpty()) {
JOptionPane.showMessageDialog(null, "Får...
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)) {
...
okay thank you like this?
returnValue = TheClassName.theMethodName(tal1);
okay we've been told to use isdigit but I don't know how to use it...
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) == '-') {
...
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?
okay something like this?
for (i=0; i<s.length(); i++)
if (s.charAt(i) == '')
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?
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....
like this?
int result = (num4 + num5);
System.out.println(result);
okay what is assignment statement?
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);
...
The result of what 341+44 is
Okay
int num4 = Integer.parseInt(num2);
int num5 = Integer.parseInt(num1);
What am I going to put in my print code?
I understand I changed my string to 341+44 and tecken+1 prints out 44 and 0, tecken prints out 321
Yes thank you! (tecken+1) only prints our the last number now.
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
String num2 = num.substring(tecken, 2);
String num1 = num.substring(0, tecken);
it only print out 1
like this?
int index = num.indexOf("num");
String num2 = num.substring(0, index);
String num1 = num.substring(index);
Okay like this?
String num1 = num.substring(0, 2);
String num2 = num.substring(0, 1);
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...
My code is supposed to accept two numbers and able to count in +, -, * and / (any number(any of these: +, *, -, /) any number)