0

Can someone convert this into if-else statements?

import java.util.*; public class Tuna { public static void main(String args[]){ Scanner KB = new Scanner(System.in); String dayString1, dayString2, dayString3; int day = KB.nextInt(); switch (day){ case 1: dayString1 = "Saturday"; case 2: dayString2 = "Sunday"; break; case 3: dayString3 = "Monday"; break; case 4: dayString1 = "Tuesday"; case 5: dayString2 = "Wednesday"; break; default: dayString3 = "Invalid Day"; break; } } }

31st Jan 2021, 4:35 PM
okurpants
okurpants - avatar
4 Antworten
0
U can simply use if else statement insted of cases Write like this if(day==1) Then sat Elseif(day==2 ) then sunday ...... ... esle Wednesday.
31st Jan 2021, 5:03 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
I just want to confirm if my answer is correct. Can someone post?
31st Jan 2021, 5:13 PM
okurpants
okurpants - avatar
0
no your code posted in question description is not correct... + there's lack of 'thursday' and 'friday' + why do you use 3 different variables to hold case result? + don't you want to display result?
31st Jan 2021, 7:30 PM
visph
visph - avatar
0
visph no the code is correct and no I dont wanna display any result
1st Feb 2021, 7:13 AM
okurpants
okurpants - avatar