In: Computer Science
Answer the following
Void display(int x)
Int display(int s)
Public static Double sum(double number);
Public static int sum(double y);
Is this a valid declaration? Why? _____________, _____________________
Public static Boolean result(int x)
{
If(x>0)
return 1;
} __________________________
cout << (10 * count) << “ “ ;
________________
total += score ;
system.println(“New Total is”);
system.printf(“%d,%n,%d%n%d”, ++ total, total − − ,total);
____________
while ( i <= 10)
{
if(i==8)
break;
cout<< i+ 3;
i++;
} ____________________
for(i=0;i<2;i++)
{
for(j=0;j<=3;j++)
{
cout<< “Hi”;
}
cout<<’*’;
} __________________________
Answer:
What is the difference between these two methods?
Write a one line of code to generate random numbers from 35 to 55.
int
randInt = 35 +
rand.nextInt(21
);
Draw the UML diagram for a switch statement with 4 cases .
Write a while loop to output the value of the variable x starting from 5, decreasing it by 0.5 each time, as long as x remains positive.
double x = 5;
while(x>0) {
System.out.println(x);
x -= 0.5;
}
Write a for loop to display the square of the first 25 odd positive integers
int x = 1;
while(x<50) {
System.out.println(x*x);
x += 2;
}
Write a method called Test that takes one argument of type int and returns a bollean value. The method should return true if the integer is less than 100.Otherwise it should return False .
public static boolean Test(int x) {
if ( x < 100 )
return true;
return false;
}
For the above method in # 8 write a main method with declarations and method call statement which assigns the return value to a variable.
public static void main(String[] args) {
boolean b = Test(10);
}
Given method declaration statements before main
Public static Double sum(double number);
Public static int sum(double y);
Is this a valid declaration? Why?
No, This is not a valid declaration because "public" and "double" keyword should start with lower case.
What is wrong with the following code?
Public static Boolean result(int x)
{
If(x>0)
return 1;
}
Keyword "public" and "boolean" should be lower case.
Assume the code below is part of a complete program, what will be the output of the code?
for ( int count = 1; count < 100; count++);
cout << (10 * count) << “ “ ;
Output : 10, 20, 30, ...... 980, 990
int total=75,score=20;
total += score ;
system.println(“New Total is”);
system.printf(“%d,%n,%d%n%d”, ++ total, total − − ,total);
Output :
96
96
95
int i = 1;
while ( i <= 10)
{
if(i==8)
break;
cout<< i+ 3;
i++;
}
Output:
45678910
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<=3;j++)
{
cout<< “Hi”;
}
cout<<’*’;
}
Output :
HiHiHiHi*HiHiHiHi
Hope you like it
Any Query? Comment Down!
I have written for you, Please upvote the answer as it encourage us to serve you Best !