Java编写一个程序,有四个整数分别用a,b,c,d表示,请用条件运算符找出其中最大值(只要Jav

求java大神!!!~

呵呵第一个程序,你自己可以上机运一下嘛!

接受用户输入的10个整数,并输出这10个整数的最大值,代码如下:
public class MaxNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int[] arrayInt = new int[10]; System.out.println("请输入10个整数:"); // 输入10个整数 for (int i = 0; i < 10; i++) { int nextInt = scanner.nextInt(); arrayInt[i] = nextInt; } // 排序 for (int i = 0; i < arrayInt.length - 1; i++) { for (int j = 0; j < arrayInt.length - i - 1; j++) { if (arrayInt[j] < arrayInt[j + 1]) { int temp = arrayInt[j]; arrayInt[j] = arrayInt[j + 1]; arrayInt[j + 1] = temp; } } } // 最大值 int maxNum = arrayInt[0]; System.out.println("10个整数的最大值:" + maxNum); }}运行效果:




    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("输入a:");
        int a = scanner.nextInt();
        System.out.print("输入b:");
        int b = scanner.nextInt();
        System.out.print("输入c:");
        int c = scanner.nextInt();
        System.out.print("输入d:");
        int d = scanner.nextInt();
        int maxAB, maxCD;
        System.out.println("最大值是:" + ((maxAB = a > b ? a : b) > (maxCD = c > d ? c : d) ? maxAB : maxCD));
    }



import java.util.Scanner;

public class Max_num {
public static void main(String[] args) {
int[] num;
Scanner in = new Scanner(System.in);
num = new int[4];
System.out.println("\n本程序可以找出四个整数的最大值。\n");
for (int i = 0; i < 4; ++i) {
System.out.printf("请输入第%d个数,%c = ", i + 1, 'a' + i);
num[i] = in.nextInt();
}
int max = num[0];
for (int i = 1; i < 4; ++i)
max = num[i] > max ? num[i] : max;
System.out.println("\n这四个数的最大值为:" + max);
}
}

public class Test {

 public static void main(String[] args) {

  int a = 1;

  int b = 5;

  int c = 7;

  int d = 3;

  System.out.println(a < b ? (b < c ? (c < d ? d : c) : (b < d ? d : c)) : (a < c ? (c < d ? d : c) : (a < d ? a : c)));

 }


int max = a > b ? a : b ;
max = max > c ? max : c ;
max = max > d ? max : d ;
System.out.println ( max + "" ) ;

没有说必须在一句内完成吧?
int x = a > b ? a : b ;
x = x > c ? x : c;
x = x ? d ? x : c;

编写一个实现四则运算的JAVA程序
答:import java.text.DecimalFormat;import java.util.Scanner;public class Zhidao { public static void main(String[] args) { String condition = "";Zhidao zhidao = new Zhidao();do{ Scanner scanner = new Scanner(System.in);try{ System.out.print("请输入第一个数:");double x = ...

java编写一个程序:假设一个车牌号码由三个字母和四个数字组成,编写一个...
答:public static void main(String[] args) {String str= "";int n=0;int c=0;for (int i = 0; i < 7; i++) {if(flag()){c++;str+=c<4? charA():charB();continue;}n++;str+=n<5? charB():charA();}System.out.println(str);}private static boolean flag(){int i=(...

编写一个程序,根据给定的四个浮点数,计算并输出他们的和,平均值。
答:import java.util.Scanner;public class MyClass {public static void main(String[] args) {Scanner scanf = new Scanner(System.in); //构造扫描仪float num[] = new float[4]; //4个浮点数float sum = 0; //和System.out.print("请输入四个浮点数:");for(float i:num) {i ...

用java语言编程:有1、2、3、4四个数字,能组成多少个互不相同且无重复...
答:private static String num="";public static void main(String[] args) throws Exception {//主函数 int[] arr={1,2,3};//给一个数组 int count=3;//给位数 num(arr,count);//调用① System.out.print(num);//输出用逗号拼接的全部数字(可以用逗号拆分,然后算长度)} //arr 数组, ...

编写一个java程序当键盘输入为wasd这四个按键中的其中一个输出对应的...
答:public static void test1() {Scanner sc = new Scanner(System.in);String in = sc.next();if (in.equals("w") || in.equals("W")) {System.out.println("方向向上");} else if (in.equals("s") || in.equals("S")) {System.out.println("方向向下");} else if (in.equals...

编写一个Java程序,它能产生从0~9的十个数字中随机取出4个不重复的数...
答:import java.util.Random;public class test{ public static void main(String[] args){ Random ran = new Random();StringBuffer sb = new StringBuffer();int i = 0;while(i < 4){ int t = ran.nextInt(9);if(sb.indexOf(String.valueOf(t)) == -1){ sb.append(t);i++;} ...

使用JAVA编写一个简单的银行存取款程序
答:另一个构造方法带4个参数分别初始化4个属性(带数据有效性验证)。/ public Account(String id, int password, String name, double balence) { this.id = id;this.password = password;this.name = name;this.balence = balence;} / 查询余额 / public static double selectMoney(Account account...

用Java编写一个程序
答:package com.test;import javax.swing.JFrame ;import javax.swing.JList ;import java.util.Vector ;import javax.swing.BorderFactory ;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.ListSelectionModel ;import javax.swing.JScrollPane ;import javax.swing.AbstractListModel...

java编写一个奶茶点单程序代码怎么写?
答:以下是一个简单的Java程序,用于实现奶茶点单功能。这个程序可以让用户选择奶茶的口味、大小、加料等选项,并计算订单的总价。import java.util.Scanner;public class MilkTeaOrder { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);System.out.println("欢迎来到...

java编写程序,创建一个整型4×4矩阵,并将其输出显示。
答:int a[][] = {{0,2,4,6},{1,3,5,7},{2,4,6,8},{3,5,7,9}};for(int i = 0; i < a.length; i++){ for(int j = 0; j

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网