1. Write Java statements to accomplish each of the following tasks a. Declare va
ID: 3601079 • Letter: 1
Question
1. Write Java statements to accomplish each of the following tasks a. Declare variable sum of type int and initialize it with 0 b. Print passed' if a grade variable is greater than or equal to 50, and failed' if the grade is les than 50 c. Add variable x to variable sum, and assign the result to variable sum 2. What does the following statement do? (Explain in English) System.out.println(x21 "Odd" "Even" 3. Develop a Java application that calculates and prints the sum of the integers from to 10. Use a while statement to loop through the calculation and increment statements. 4. What is the result of executing this program? public class Mystery2 public static void main( String[] args ) int count = 1; while countExplanation / Answer
1.
a.)int sum=0;
b.)if(grade>=50)
{
System.out.println("Passed");
}
else if(grade<50)
{
System.out.println("Failed");
}
c.)sum=sum+x;
2. What does the Following Statement Do?
System.out.println(x%2==1 ? "odd" : "Even");
which is a Ternary/Conditinal Expression.
It checks whether the given number is divisible 2 or not.
if it yes then print "Even" otherwise will print "odd".
3.Java Application to print The Sum of Integers from 1 to 10 ussing whileloop.
Source Code:
----------------------
package tasks;
public class Mystery
{
public static void main(String[] args)
{
int sum=0,i=1;
while(i<=10)
{
sum=sum+i;
i++;
}
System.out.println("The Sum of Integer Numbers from 1 to 10 is:"+sum);
}
}
sample output:
------------------------
The Sum of Integer Numbers from 1 to 10 is:55
4. What is The Result of Executing this Program?
public class Mystery
{
public static void main(String[] args)
{
int count=1;
while(count<=10)
{
System.out.println(count%2==1? "******":"+++++++");
count=count+1;
}
}
}
Output:
----------------------
******
+++++++
******
+++++++
******
+++++++
******
+++++++
******
+++++++
5.
package tasks;
import java.util.Scanner;
public class Largest_number
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int counter,large = 0,number;
counter=10;
int array[]=new int[counter];
System.out.println("Enter "+counter+" Integer Numbers:");
for(int i=0;i<counter;i++)
{
array[i]=sc.nextInt();
}
number=array[0];
for(int i=0;i<counter;i++)
{
if(number<array[i])
{
number=array[i];
large=number;
}
}
System.out.println("The Largest Number is:"+large);
sc.close();
}
}
Sample output:
-------------------------------
Enter 10 Integer Numbers:
10
20
30
40
50
60
70
80
90
10
The Largest Number is:90
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.