menu
QAmmunity.org
Login
Register
My account
Edit my Profile
Private messages
My favorites
Ask a Question
Questions
Unanswered
Tags
Categories
Ask a Question
What will be the output of the following code?int p = 3,ch = 2;switch(ch){case 1: System. Out. Println("The square is: " + p*p);break;case 2: System. Out. Println("The cube is: " + p*p*p);break;default:
asked
Nov 5, 2023
227k
views
2
votes
What will be the output of the following code?int p = 3,ch = 2;switch(ch){case 1: System. Out. Println("The square is: " + p*p);break;case 2: System. Out. Println("The cube is: " + p*p*p);break;default: System. Out. Println("No Output Value");}
Computers and Technology
high-school
Netsurfer
asked
by
Netsurfer
8.1k
points
answer
comment
share this
share
0 Comments
Please
log in
or
register
to add a comment.
Please
log in
or
register
to answer this question.
1
Answer
9
votes
“The cube is: 27”
or p^3
The switch function uses the ch int and identifies a matching case. Because ch is 2
We use case 2
Thus the following line at the top is printed.
Then automatically breaks the function, so we don’t continue.
Kostas Andrianos
answered
Nov 10, 2023
by
Kostas Andrianos
8.5k
points
ask related question
comment
share this
0 Comments
Please
log in
or
register
to add a comment.
← Prev Question
Next Question →
Related questions
asked
Oct 16, 2017
77.7k
views
9. Consider the following code. int x = 2; switch (x) { case 1: x += 3; case 2: x += 5; case 3: x += 7; default: x += 10; } Which syntax correctly prints an array? for (int n = 1; n <= x.length; n++) { System.out.println(x[n]); }
Jonesinator
asked
Oct 16, 2017
by
Jonesinator
8.1k
points
Computers and Technology
high-school
1
answer
2
votes
77.7k
views
asked
Mar 11, 2020
229k
views
What is wrong with the following switch statement? int ans; System.out.print("Type y for yes or n for no"); ans = scan.nextInt(); switch (ans) { case 'y': case 'Y': System.out.println("You said yes");break;
Lancepants
asked
Mar 11, 2020
by
Lancepants
8.5k
points
Computers and Technology
high-school
1
answer
1
vote
229k
views
asked
Jul 16, 2024
40.6k
views
What is the output of running class C? class A { public A() { System.out.println("The default constructor of A is invoked"); } } class B extends A { public B() { System.out.println("The default constructor
Tomaoq
asked
Jul 16, 2024
by
Tomaoq
7.8k
points
Computers and Technology
high-school
1
answer
3
votes
40.6k
views
Ask a Question
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.
9.5m
questions
12.2m
answers
Other Questions
The book shows how to add and subtract binary and decimal numbers. However, other numbering systems are also very popular when dealing with computers. The octal (base 8) numbering system is one of these.
Seven basic internal components found in a computer tower
describe an advance in technology that makes life more enjoyable. what discoveries contribute to this technology?
Disadvantages of using animation in advertising? advantages and disadvantages of using animation for education? advantages and disadvantages of using animation in entertainment?
Explain why binary codes are used to represent characters, numbers and symbols :)
Twitter
WhatsApp
Facebook
Reddit
LinkedIn
Email
Link Copied!
Copy
Search QAmmunity.org