public class Conditional{ public static void main(String args[ ]){ int x=4; System.out.println(“value is “ + ((x>4) ? 99.9 :9)); } }
时间: 2024-04-26 09:22:38 浏览: 14
这段 Java 代码的输出结果是 "value is 9"。这是因为三目运算符(?:)中的条件为 x>4,而 x 的值为 4,因此条件不成立。三目运算符的语法是:条件表达式 ? 表达式1 : 表达式2。如果条件表达式为 true,三目运算符返回表达式1的值,否则返回表达式2的值。在这个例子中,表达式1的值为 99.9,表达式2的值为 9,由于条件不成立,因此返回表达式2的值,即9。最终结果为字符串 "value is 9"。
相关问题
All of Statistics
All of Statistics is a comprehensive textbook on statistics written by Larry Wasserman, a professor of statistics at Carnegie Mellon University. The book provides a thorough introduction to statistical concepts and methods, including probability theory, statistical inference, regression analysis, and hypothesis testing. It is intended for students and researchers in a variety of fields, including mathematics, engineering, computer science, and the natural and social sciences.
The book is divided into six parts:
1. Probability: This section covers basic concepts in probability theory, including random variables, probability distributions, conditional probability, and Bayes' rule.
2. Statistical Inference: This section covers the principles of statistical inference, including point estimation, confidence intervals, and hypothesis testing.
3. Linear Regression: This section covers linear regression models, including simple linear regression, multiple regression, and logistic regression.
4. Nonparametric Methods: This section covers nonparametric methods, including rank-based tests and density estimation.
5. Bayesian Methods: This section covers Bayesian methods, including Bayes' theorem, Bayesian inference, and hierarchical models.
6. Advanced Topics: This section covers advanced topics in statistics, including high-dimensional data analysis, time series analysis, and causal inference.
Throughout the book, Wasserman emphasizes the importance of understanding the underlying concepts and principles of statistics, rather than just memorizing formulas and procedures. He also provides numerous examples and exercises to help readers develop their skills in statistical analysis.
Overall, All of Statistics is a highly-regarded textbook that provides a comprehensive introduction to statistical theory and methods. It is suitable for undergraduate and graduate students, as well as researchers and practitioners in a range of fields.
package demo; import java.util.HashMap; import java.util.Scanner; public class exercise333 { private static Scanner scanner; /** * 学生信息集合 */ private static HashMap<String,Student> map; public static void main(String[] args) { // TODO Auto-generated method stub select(); } private static void select() { System.out.println("请输入学号:"); Scanner sc = new Scanner(System.in); String nub = sc.nextLine(); Student student = map.get(nub); if(Student = null) System.out.println("没有查询到该学生!"); else System.out.println(student.toString()); } } static class Student{ private String sno; /** * 学号 */ private String name; /** * 姓名 */ private String major; /** * 专业 */ private String score; /** * 成绩 */ public String toString() { return "学生信息{"+ "学号='" + sno + '\'' + "姓名='" + name + '\'' + "专业='" + major + '\'' + "成绩='" + score + '\'' + '}'; } public String getSno() { return sno; } public void setSno(String sno) { this.sno = sno; } public String getName() { return name ; } public void setName(String name) { this.name = name; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } public String getScore() { return score; } public void setScore(String score) { this.score =score; } public Student(String sno,String name,String major,String score) { this.sno = sno; this.name = name; this.major = major; this.score = score; } }
There is a syntax error in line 29 of the code. The conditional statement should have parenthesis around it.
Change:
if(Student = null)
To:
if(student == null)
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)