0

I was looking to create a project but i'm a new java programmer and i'm not ablo to create it.

public class Funzioni {

    public static void main(String[] args) {
        System.out.println("E' una funzione algebrica o aritmetica?");


    }

}

If the answer is algebrica, so... if the answer is aritmetica, so..

Can someone help me with the if costruct? thnak you so much

frlaka
  • 9
  • 2
  • is the value in the args array? – ave4496 Oct 30 '16 at 08:21
  • can you describe your problem more precise? – Statham Oct 30 '16 at 08:23
  • import java.util.Scanner; public class Funzioni { public static void main(String[] args) { System.out.println("E' una funzione algebrica o aritetica?"); Scanner userlnputScanner = new Scanner(System.in); userlnputScanner.nextLine(); boolean algebrica = true; if E' una funzione algebrica o aritetica?==algebrica – frlaka Oct 30 '16 at 08:32
  • why it doesn't work? – frlaka Oct 30 '16 at 08:32

1 Answers1

0

Good morning, frlaka.

You just need to read from keyboard a String.

import java.util.Scanner;

public class Funzioni {

    public static void main(String[] args) {
        System.out.println("E' una funzione algebrica o aritmetica?");
        String value;
        Scanner s = new Scanner(System.in);
        value=s.nextLine();
        if (value.equals("algebrica")){
            // do something
        } else if (value.equals("aritmetica")){
            // do something
        }
    }
}

Have a good day!

  • import java.util.Scanner; public class Funzioni { public static void main(String[] args) { System.out.println("E' una funzione algebrica o aritetica?"); Scanner userlnputScanner = new Scanner(System.in); userlnputScanner.nextLine(); boolean algebrica = true; if E' una funzione algebrica o aritetica?==algebrica Why it doesn't work? – frlaka Oct 30 '16 at 08:32
  • Because you can't compare a String with a Boolean variable. Try to use my example and you'll see it works. – Carlos Vázquez Losada Oct 30 '16 at 08:34
  • I have seen it. I don't understandt in which case i have to use string and when i have to use the boolean variable – frlaka Oct 30 '16 at 08:37
  • When you run your program, in your console, first of all, will appear "E' una funzione algebrica o aritmetica?" and then, the console will allow you to write something. If you write algebraica, then, the variable 'value' has "algebraica" value. In the if/else clause, your program will compare 'value' value with "algebraica". If you have written "algebraica", this will return 'true', so you execute what is inside the if (you could add a System.out.println("Algebraica selection");) – Carlos Vázquez Losada Oct 30 '16 at 08:41