1)code:
=====================================
public class MyClass {
public static void main(String args[]) {
int day=5;
switch(day){
case 1:System.out.println("Monday");
case 2:System.out.println("Tuesday");
case 3:System.out.println("Wednesday");
case 4:System.out.println("Thursday");
case 5:System.out.println("Friday");
case 6:System.out.println("Saturday");
case 7:System.out.println("Monday");break;
default:System.out.println("Invalid day");
}
}
}
=================================================
The o/p is :
Friday
Saturday
Sunday
because , it will enter the switch with value of day as 5. So it checks for case 5, and it prints the Friday ,but since we dont have a break statement , the subsequent cases also exceuted.
so case 6 is executed and Saturday is printed. again we dont have a break statement .So it goes to next case 7 and prints Sunday.
now in case 7 we have a break statement ,so switch is exited and program stops running.
===========================================================
2)program:
============================================================
public class MyClass {
public static void main(String args[]) {
int x=20;
int y=40;
if(x>10){
if(y>50){
System.out.println("Hello,Frined.");
}else{
System.out.println("GoodBye,Frined.");
}
}else{
if(y>50){
System.out.println("Hello,Enemy.");
}else{
System.out.println("GoodBye,Enemy.");
}
}
}
}
=================================================
The O/p is GoodBye,Friend
because ,since x=20; if(x>10) -> (20>10)is true and it enters the if statement .
next if(y>50) -> (40>50) is false , so it will go to else and prints the " GoodBye Friend. "
it will not go to else of line 13 ,since we entered already the corresponding if in line 7.
========================================================================
Please upvote and comment for doubts
need help with java questions The following snippet of code would produce what outcome? public static...
Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...
THIS CODE SHOULD BE MODIFIED TO READ SuperMarket.dat instead of Inputting and Outputting. SuperMarket.dat Monday 4 Monday 6 Monday 2 Tuesday 3 Tuesday 2 Wednesday 3 Wednesday 5 Wednesday 7 Thursday 5 Friday 4 Friday 3 Friday 4 Saturday 8 Saturday 8 Saturday 8 Sunday 0 QUESTION: Write the control break code, including the code for the dayChange() method, in the main() method. // SuperMarket.java - This program creates a report that lists weekly hours worked // by employees of...
I need to create a Java class file and a client file that does the following: Ask user to enter Today’s date in the form (month day year): 2 28 2018 Ask user to enter Birthday in the form (month day year): 11 30 1990 Output the following: The date they were born in the form (year/month/day). The day of the week they were born (Sunday – Saturday). The number of days between their birthday and today’s...
Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program that prompts the user to enter a year, month, day of month and it displays the name of the week. Here is my source code. I need it broke down into a flowchart. public static void main(String[] args) { //all variables are initialized to 0, because local variables require at least an initial value before use Scanner input = new...
Answer the following questions with the given data set: 1 Distribution of accidents Accidents Weekunday Monday Tuesday Wednesday Thursday Day of the Mon Week |- | 10|29 Frequency 36 Friday Saturday 41 50 63 40 PrintDone A researcher wanted to determine whether certain accidents were uniformly distributed over the days of the week. The data show the day of the week for n =299 randomly selected accidents. Is there reason to believe that the accident occurs with equal frequency with...
Hello, I have a bug in my code, and when I run it should ask the user to enter the month and then the year and then print out the calendar for the chosen month and year. My problem with my code is that when I run it and I enter the month, it doesn't ask me for the year and it prints all the years of the month I chose. Please help! Code: #include "calendarType.h" #include <iostream> using namespace...
I have this code and need this to be written and applied with an array? How do I process this? Also What would I apply this with flowchart? Module main() Call getDailyProfit() Call calculateWeeklyProfit() Call main() Module getDailyProfit() // Declare all variables and establish the array Constant Real SIZE = 7 Declare String days[SIZE] = Sunday, Monday, Tuesday, Thursday. Friday, Saturday Declare Real days Declare Real number Declare Real Index //Prompt the user for profit information for Sunday Display “How...
Hello, i need help with this homework: Code provided: public class DirectedWeightedExampleSlide18 { public static void main(String[] args) { int currentVertex, userChoice; Scanner input = new Scanner(System.in); // create graph using your WeightedGraph based on author's Graph WeightedGraph myGraph = new WeightedGraph(4); // add labels myGraph.setLabel(0,"Spot zero"); myGraph.setLabel(1,"Spot one"); myGraph.setLabel(2,"Spot two"); myGraph.setLabel(3,"Spot three"); // Add each edge (this directed Graph has 5 edges, // so we add 5 edges) myGraph.addEdge(0,2,9); myGraph.addEdge(1,0,7); myGraph.addEdge(2,3,12); myGraph.addEdge(3,0,15); myGraph.addEdge(3,1,6); // let's pretend we are on...
Please help me write a program flowchart! I have been struggling for quite some time, and mainly I need the answer. Thank you ! room Hef main(); #run order: date waitlist budget result numGuests = guests() weekDay = date() waitList = waitlist(weekDay) hotelBudget - budget() print("Day:, displayWeek (weekDay)) print("Budget: ", hotel Budget) result(waitList, numGuests, room(numGuests, hotelBudget)) def guests(): numGuests - while numGuests <=@ or numGuests > 8: try: numGuests = (int(input("Please enter number of guests:"))) if numGuests > 8: print("Maximum...