| |

VerySource

 Forgot password?
 Register
Search
View: 567|Reply: 2

An error occurred while using the basic ternary operation of java.

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-17 07:40:01
| Show all posts |Read mode
class example1
{
public void xy (char x)
{

char i = x;
char y = (char) (i + 32);
boolean flag = i == 65;
System.out.println (flag);
System.out.println (y);
    flag? i: (char) (i + 32);
System.out.println (i);
}
public static void main (String [] args)
{
example1 e = new example1 ();
e.xy ('A');
}
}


Error message:
example1.java:11: not a statement
    flag? i: (char) (i + 32);
         ^
1 error
Reply

Use magic Report

1

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-1-22 09:27:01
| Show all posts
flag? i: (char) (i + 32);
Type mismatch: cannot convert from char to boolean

To:
i = flag? i: (char) (i + 32);
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-22 13:54:02
| Show all posts
Thank you very much, I understand
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list