本文介绍了我如何通过三元运算符进行提问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 import java.util.Scanner; public class 字符{ char ch; int i; public void acceptData(){ Scanner in = new Scanner(System.in); System.out.println( 输入任何字符); ch = in.nextLine()。charAt( 0 ); i =( int )ch; // public void check(){ boolean b1 =( 91 > i> 64 ); if (b1){ String str = b1? 大写字母:rts; } boolean b2 =( 123 > i> 95 ); String rts = b2? 小写: 特殊字符; } public static void main( String args []){ Character obj = new Character(); obj.acceptData(); // obj.check(); System.out.println( STR); } } 我的尝试: 在这个我尝试使用三元运算符编写prgramm并显示编译错误,我想忽略if else条件我应该做什么更正来正确运行程序?解决方案 不知道你还想做什么作为三元运算符但是你去了。 import java.util.Scanner; public class 字符{ char ch; int i; public void acceptData(){ Scanner in = new Scanner(System.in); System.out.println( 输入任何字符); ch = in.nextLine()。charAt( 0 ); i =( int )ch; // 此处三元更正 // b2使用的b2,移至顶部 boolean b2 =( 123 > i&& i> 95 ); // 在声明之前调用RTS,移到顶部 String rts = b2? 小写: 特殊字符; boolean b1 =( 91 > i&& i> ; 64 ); 字符串 str = b1? 大写字母:rts; } public static void main( String args []){ Character obj = new Character(); obj.acceptData(); // obj.check(); System.out.println( STR); } } import java.util.Scanner;public class Character {char ch;int i;public void acceptData() {Scanner in = new Scanner(System.in);System.out.println("Enter any character");ch = in.nextLine().charAt(0);i = (int) ch;//public void check() {boolean b1 = (91 > i > 64) ;if(b1){String str = b1 ? "upper case" : rts;}boolean b2 = (123 > i > 95);String rts = b2 ? "lower case" : "special character";}public static void main(String args[]) {Character obj = new Character();obj.acceptData();//obj.check();System.out.println(str);}}What I have tried:in this i tried to write the prgramm using the ternary operator and it shows the compilation error and i want to ignore the if else conditionals what are the corrections i should do to run the program correctly? 解决方案 Not sure what else you wanted done as ternary operators but here you go.import java.util.Scanner;public class Character {char ch;int i;public void acceptData() {Scanner in = new Scanner(System.in);System.out.println("Enter any character");ch = in.nextLine().charAt(0);i = (int) ch; //Ternary corrections here//b2 in use by rts, moved to topboolean b2 = (123 > i && i > 95);// RTS being called prior to being declared, moved to topString rts = b2 ? "lower case" : "special character";boolean b1 = (91 > i && i > 64) ;String str = b1 ? "upper case" : rts;}public static void main(String args[]) {Character obj = new Character();obj.acceptData();//obj.check();System.out.println(str);}} 这篇关于我如何通过三元运算符进行提问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-23 17:04