Answer the question
In order to leave comments, you need to log in
Is the ternary operator used correctly?
Hello! I have a code that is written with a conditional statement.
package ru;
import java.util.Scanner;
public class Ones {
public static void main(String[] args) {
try (Scanner input = new Scanner(System.in)) {
int a;
int b;
int c;
int d;
int max;
System.out.println("Please Enter number A");
a = input.nextInt();
System.out.println("Please Enter number B");
b = input.nextInt();
System.out.println("Please Enter number C");
c = input.nextInt();
System.out.println("Please Enter number D");
d = input.nextInt();
max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
if (d > max) {
max = d;
}
System.out.println(a + ";" + b + ";" + c + ";" + d);
System.out.println("Maximum number " + max);
}
}
}
package ru.mail.stonap;
import java.util.Scanner;
public class ones {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int a = 2, b = 4, c = 5, d = 7, max;
max = a > b ? a : b;
max = c > d ? c : d;
System.out.println(max);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question