English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

1.) Where is the error in this code sequence?
double pi = Math(PI);
System.out.println(pi);

I know it's something simple, but I can't think of it.




2.) You coded the following on lines 10-12 oc class Test.java:
String s;
int l= s.length();
System.out.println("length is " + 1);
When you compile you get the following message:
Test.java:11: variable s might not have been initialized.
int i=s.length();

1 error

Explain what the problem is and how to fix it.

2007-02-04 16:41:09 · 4 answers · asked by Chestnut C 1 in Computers & Internet Programming & Design

4 answers

First off, I'm still learning Java syntax, but I program in a variety of other languages, my favorite being c++

1.double pi = Math(PI);
the error is here, variable names are case sensetive, PI is not the same as pi, basically what your doing is making a variable equal to a function (or object, cant tell by the syntax) with the variable as the only parameter, it should be

double pi = Math(pi)
System.out.println(pi);

2. This one is simple, it is basically saying that since you declared s, you gave it NO value...ever, then your reusing it, basically what the computer is tring to say, hey you declared this variable s, and you dont know whats it in and neither do I, I sense a possible problem here....here is also an example

var S; = declare s

System.out.println(s + 100)

the output of S is totally unknown, because S will equal whatever the data previously stored in the place of S is. So S could equal, 100, 4000, -5888, any value

2007-02-04 16:50:58 · answer #1 · answered by D 4 · 0 0

a million) The programmer ought to "trick" the computing device into questioning the wanted information variety is primitive. attempt utilising moderate of hand or optical illusions. 2) The bag classification is vertical even as the series classification is horizontal. series is a lot extra worry-free and more convenient to software.

2016-11-25 02:52:32 · answer #2 · answered by dunworth 4 · 0 0

1. use pi = Math.PI
2. initialize string,
eg:- String s = "initilized";
int l = s.length();

2007-02-04 16:49:36 · answer #3 · answered by Rhul s 2 · 0 0

1. Should be Math.PI
2. There is nothing in s, you can't take a length of nothing.

2007-02-04 16:45:13 · answer #4 · answered by JamesLeeH 2 · 0 0

fedest.com, questions and answers