Summer, 2018 CCIS 105: Final Exam NAME: DATE: 7/13/18 1. Using a loop, write a p
ID: 3913026 • Letter: S
Question
Summer, 2018 CCIS 105: Final Exam NAME: DATE: 7/13/18 1. Using a loop, write a program that prints all even numbers from 2 to 2000. Demonstrate using all three looping structures. 2. Create a class named Numbers whose main method prompts the user to enter two integers. The main method should pass the value of the integers to two additional meth and difference 0 to perform the calculations. The sum within the method, and the difference method should return and display the results of the calculation in the main. ods, sum method should display the results 3. A method is declared as: public static void showResults(double d, int i). Write a statement to call the method.Explanation / Answer
class EvenWithAllLoops {
public static void main(String[] args) {
int i=0;
for (i=2;i<=20;i++ ) {
if (i%2==0) {
System.out.println(i);
}
}
i=2;
while(i<=20){
if (i%2==0) {
System.out.println(i);
}
i++;
}
i=2;
do{
if (i%2==0) {
System.out.println(i);
}
i++;
}while(i<=20);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.util.*;
class Numbers{
public static void sum(int num1,int num2){
System.out.println("Sum is "+(num1+num2));
}
public static int difference(int num1,int num2){
// System.out.println("difference is "+(num1+num2));
return (num1-num2);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int num1=sc.nextInt();
int num2=sc.nextInt();
sum(num1,num2);
System.out.println("difference is "+difference(num1,num2));
}
}
///////////////////////////////////////////////////////////////////////////////////////////
class callMe {
public static void showResult(double d, int i){
System.out.println("i am called with "+d +" and "+i);
}
public static void main(String[] args) {
showResult(0.01,5);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.