Kindly help me to find the largest number among four numbers by conditional loop "?" .Fast. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Kindly help me to find the largest number among four numbers by conditional loop "?" .Fast.

java only

23rd Sep 2017, 5:38 PM
Maneesh Kumar Singh
Maneesh Kumar Singh - avatar
5 Answers
+ 3
This is a conditional loop. Which loop structure are you wanting? for foreach/for in while do while be more specific all of the above take a condition and are conditional loops.
23rd Sep 2017, 6:18 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
public class Program { public static void main(String[] args) { int[] nums = { 234, 823, 492, 196}; int largest = 0; for(int i = 0; i < nums.length; ++i) { if ( nums[i] > largest) largest = nums[i]; } System.out.println(largest); } }
23rd Sep 2017, 6:12 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
i am asking by conditional loop"?"
23rd Sep 2017, 6:13 PM
Maneesh Kumar Singh
Maneesh Kumar Singh - avatar
+ 1
i need it.
23rd Sep 2017, 6:14 PM
Maneesh Kumar Singh
Maneesh Kumar Singh - avatar
+ 1
Pick one: public class Program { public static void main(String[] args) { int[] nums = { 234, 823, 492, 196}; int largest = 0; for(int i = 0; i < nums.length; ++i) { largest = nums[i] > largest ? nums[i] : largest; } System.out.println(largest); largest = 0; int j = 0; while (j < nums.length) { largest = nums[j] > largest ? nums[j] : largest; j++; } System.out.println(largest); largest = 0; for(int num: nums) { largest = num > largest ? num : largest; } System.out.println(largest); } }
23rd Sep 2017, 6:29 PM
ChaoticDawg
ChaoticDawg - avatar