+ 1

Primitive Operators

I am so confused with this one, I dont know where am I wrong. My code: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double pi = 3.14; //your code goes here int var; var = scanner.nextInt(4); double result = 2* pi * var; System.out.println("double result"); } }

8th Jul 2021, 7:59 AM
Marc Cid Salmeron
Marc Cid Salmeron - avatar
9 Réponses
+ 5
var = scanner.nextInt(4);//take off the # 4
8th Jul 2021, 8:55 AM
JRAMAHES
JRAMAHES - avatar
+ 3
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double pi = 3.14; //your code goes here int var; var = scanner.nextInt(); double result = 2 * pi * var; System.out.println(result); } } bro you should remove 4 from the scanner code line var = scanner.nextInt(4); should be replaced by var = scanner.nextInt();
8th Jul 2021, 9:01 AM
Mayank Dhull
Mayank Dhull - avatar
+ 1
you were so close. So I think you can do it like this. double pi = 3.14 * 2; int n = scanner.nextInt(); double result = pi * n ; System.out.println(result);// here do it without quote, because the result is name of the variable.
8th Jul 2021, 8:20 AM
JRAMAHES
JRAMAHES - avatar
+ 1
oh, okay okay, thank you guys :) Im pretty newbie with this (my second day trying to learn by myself so, im pretty lost haha.
8th Jul 2021, 9:40 AM
Marc Cid Salmeron
Marc Cid Salmeron - avatar
0
It doesnt works for me, int n = scanner.nextlnt(4); double result = pi * n; System.out.println(result); The error I get: /usercode/Main.java:9: error: cannot find symbol int n = scanner.nextlnt(4); ^ symbol: method nextlnt(int) location: variable scanner of type Scanner 1 error
8th Jul 2021, 8:45 AM
Marc Cid Salmeron
Marc Cid Salmeron - avatar
0
I dont think the error comes from that linea, the error that I get is: /usercode/Main.java:12: error: '.class' expected System.out.println(double result); ^ /usercode/Main.java:12: error: ';' expected System.out.println(double result); And the code that Im using atm: int var; var = scanner.nextInt(4); double result = 2* pi * var; System.out.println(double result);
8th Jul 2021, 9:06 AM
Marc Cid Salmeron
Marc Cid Salmeron - avatar
0
oh! Okay thank you both, it worked, but I dont understand why it worked? Im pretty dumb still, can I ask you, why shouldnt I put the 4? I mean, shouldnt I give the information that the Var is 4?
8th Jul 2021, 9:09 AM
Marc Cid Salmeron
Marc Cid Salmeron - avatar
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double pi = 3.14; //your code goes here int radius = 2; System.out.println(radius*pi*scanner.nextInt()); } }
13th Feb 2022, 9:54 AM
Salman
Salman - avatar