Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
What is the wrong of this code? need help.
public class TailRrecursion {
public static void tail(int i) {
if (i > 0) {
System.out.print(i + "");
tail(i - 1);
}
}
}
For a start, you are missing curly { braces
see
public class Tail-recursion{
public static void tail(int i) {
if(i>0){
System.out.print (i +"");
tail(i-1);
}
}
} // and here
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is just a simple query if anyone knows why I am facing this error I would appreciate the help.
The problem is simple java if else if else loop problem .
so I tried to make syntax as correct as possible.
The code here below is the one I am executing.
public class ifelseloop {
public static void main(String[] args){
// int a = 20;
// int b = 20;
String city = "Delhi";
if (city == "madras") {
System.out.println("the city is not delhi its madras");
}else if(city == "chennai") {
System.out.println("the city is not delhi its chennai");
}else if(city == "bartar") {
System.out.println("the city is bartar");
}else {
System.out.println(city);
}
}
}
and the error that I am getting is this.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at ifelseloop.main(ifelseloop.java:2)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am trying to calculate the factorial of the integer user inputs, but it does not return anything. Why?
Thanks.
import java.util.Scanner;
`class App {
public static int factorial(int n) {
if (n == 0) {
return 1;
} else {
int recurse = factorial(n - 1);
int result = n * recurse;
return result;
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter an integer to calculate its factorial: ");
int users = input.nextInt();
factorial(users);
}
}
The problem in your code is that you are have not giving a print statement for displaying factorial of the number entered. Just returning a value will not print it. If you are working in BlueJ environment, you can only use the code by directly executing the method factorial. Thank You.
The problem in your code is that , you are have not given a print statement for >displaying factorial of the number entered.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
The following code compiles, but when I ran it, it didn't enter the while-loop. Why ?
while (Str1.equals(Str2)); {
count = 1;
while (count <= maxCount); {
System.out.print(something1);
count = count + 1; } }
Remove the semi colon, semicolon is added only for do-while.Here is your code:
while (Str1.equals(Str2))
{
count = 1;
while (count <= maxCount)
{
System.out.print(something1);
count = count + 1;
}
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
public class Try1 {
public static void main(String[] args) {
char ch;
for(ch='a' ;ch<='z'; ch++);
{
System.out.println(ch);
}
}
}
could not get output
try
public static void main(String[] args) {
char ch;
for(ch='a' ;ch<='z'; ch++)
{
System.out.println(ch);
}
}
You've used ; after for loop.
for this "for(ch='a' ;ch<='z'; ch++);" statement, are you sure about last semicolumn, it breaks your for loop right there only.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I can't seem to get the last "i" in this code to fully function, it wont respond to the initial "i", just tells me that it "cannot find symbol". What am I doing wrong?
public void fillCB (JComboBox cb){
String sqlQueryCB = "select namn from ANSTALLD order by namn";
try {
ArrayList<String> listaAnstalld = idb.fetchColumn(sqlQueryCB);
for(int i = 0; i < listaAnstalld.size(); i++); {
cb.addItem(listaAnstalld.get(i));
}
}
catch(Exception e)
{
}
you have a semicolon at the end of your for loop, before the opening brace.
for(int i = 0; i < listaAnstalld.size(); i++); {
That semicolon closes the for loop. should remove it.
because of this, the contents of your block will not be in the scope of the for loop(and therefore not in the same scope that i is in).