+ 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"); } }
9 odpowiedzi
+ 5
var = scanner.nextInt(4);//take off the # 4
+ 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();
+ 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.
+ 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.
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
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);
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?
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());
}
}