actually the problem is like thisJoel Christophel wrote:Your problem is a misplaced semicolon.
Luan Vo wrote:
actually the problem is like thisJoel Christophel wrote:Your problem is a misplaced semicolon.
//PROBLEM3 - if x has a value of 4, print "ddd", else print "eee"
result = "";
if (x == 4)
result = result + "ddd";
else
result = result + "eee";
System.out.println("3.\t" + result);
That is the original prob
Joel Christophel wrote:
Luan Vo wrote:
actually the problem is like thisJoel Christophel wrote:Your problem is a misplaced semicolon.
//PROBLEM3 - if x has a value of 4, print "ddd", else print "eee"
result = "";
if (x == 4)
result = result + "ddd";
else
result = result + "eee";
System.out.println("3.\t" + result);
That is the original prob
Well that should work now that there is no semicolon after the if statement. Does it not?
Bear Bibeault wrote:It is highly recommended to use braces for the if and else parts even if they are single statements.
Otherwise, your code is harder to read and can be fragile. (and is prone to errors)
Luan Vo wrote:
Joel Christophel wrote:
Luan Vo wrote:
actually the problem is like thisJoel Christophel wrote:Your problem is a misplaced semicolon.
//PROBLEM3 - if x has a value of 4, print "ddd", else print "eee"
result = "";
if (x == 4)
result = result + "ddd";
else
result = result + "eee";
System.out.println("3.\t" + result);
That is the original prob
Well that should work now that there is no semicolon after the if statement. Does it not?
Nope there are three error in this problem
Number 1 is (reached end of file while parsing
'else' without 'if') it's on the column result = result + "ddd";
number 2 is (cannot find the symbol and location) on conlumn ( result = result + "eee";
#3 is ( canot not find the symbol: class out and location: class java.lang.system) on System.out.println("3.... + result)
Yes i did at the begginng.Joel Christophel wrote:
Luan Vo wrote:
Joel Christophel wrote:
Luan Vo wrote:
actually the problem is like thisJoel Christophel wrote:Your problem is a misplaced semicolon.
//PROBLEM3 - if x has a value of 4, print "ddd", else print "eee"
result = "";
if (x == 4)
result = result + "ddd";
else
result = result + "eee";
System.out.println("3.\t" + result);
That is the original prob
Well that should work now that there is no semicolon after the if statement. Does it not?
Nope there are three error in this problem
Number 1 is (reached end of file while parsing
'else' without 'if') it's on the column result = result + "ddd";
number 2 is (cannot find the symbol and location) on conlumn ( result = result + "eee";
#3 is ( canot not find the symbol: class out and location: class java.lang.system) on System.out.println("3.... + result)
Well have you declared the variable result as a String?
Luan Vo wrote:
Joel Christophel wrote:
Luan Vo wrote:
Joel Christophel wrote:
Luan Vo wrote:
actually the problem is like thisJoel Christophel wrote:Your problem is a misplaced semicolon.
import java.util.*;
public class MinilabIfElse
{
public static void main(String args[])
{
//declare variables
String result;
int x;
int inputx;
//prompt for, read in a value for x
Scanner kb = new Scanner(System.in);
System.out.print("Please enter a value for x (integer): ");
inputx = kb.nextInt();
//************************************************************************
//The if-else statements in this section have syntax errors (will not compile).
//Fix each of them so that it compiles and the proper result is printed.
//************************************************************************
System.out.println("\n\n\"Common syntax errors\" section");;
x=inputx;
//PROBLEM1 - if x has a value of 4, print "ddd", else print "eee"
result = "";
if (x == 4)
result = result + "ddd";
else
result = result + "eee";
System.out.println("1.\t" + result);
//PROBLEM2 - if x has a value of 3 or 4, print "ddd", else print "eee"
result = "";
if((x==3) ||(x==4))
result = result + "ddd";
else
result = result + "eee";
System.out.println("2.\t" + result);
//PROBLEM3 - if x has a value of 4, print "ddd", else print "eee"
result = "";
if (x == 4)
result = result + "ddd";
else
result = result + "eee";
System.out.println("3.\t" + result);
Add two braces to the end of the file to close main method and class. Other than that, I get no errors.
Joel Christophel wrote:
Luan Vo wrote:
Joel Christophel wrote:
Luan Vo wrote:
Joel Christophel wrote:
Luan Vo wrote:
actually the problem is like thisJoel Christophel wrote:Your problem is a misplaced semicolon.
import java.util.*;
public class MinilabIfElse
{
public static void main(String args[])
{
//declare variables
String result;
int x;
int inputx;
//prompt for, read in a value for x
Scanner kb = new Scanner(System.in);
System.out.print("Please enter a value for x (integer): ");
inputx = kb.nextInt();
//************************************************************************
//The if-else statements in this section have syntax errors (will not compile).
//Fix each of them so that it compiles and the proper result is printed.
//************************************************************************
System.out.println("\n\n\"Common syntax errors\" section");;
x=inputx;
//PROBLEM1 - if x has a value of 4, print "ddd", else print "eee"
result = "";
if (x == 4)
result = result + "ddd";
else
result = result + "eee";
System.out.println("1.\t" + result);
//PROBLEM2 - if x has a value of 3 or 4, print "ddd", else print "eee"
result = "";
if((x==3) ||(x==4))
result = result + "ddd";
else
result = result + "eee";
System.out.println("2.\t" + result);
//PROBLEM3 - if x has a value of 4, print "ddd", else print "eee"
result = "";
if (x == 4)
result = result + "ddd";
else
result = result + "eee";
System.out.println("3.\t" + result);
Thanks youvery much! It's really good to help this kind of help out side of class. Thanks again Joel
You mean the compiler will not notice any errors. I can see several errors, egJoel Christophel wrote:You will have no errors if your code looks exactly like this:
. . .
Get off me! Here, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|