0% found this document useful (0 votes)
6 views3 pages

It 1

The document contains a Java program that demonstrates various data types, arithmetic operations, and control flow structures such as loops and conditionals. It includes commented-out sections for variable declarations, basic arithmetic, and user input handling. The main functionality focuses on calculating the sum of even numbers within a specified range using the 'findSumInRange' method.

Uploaded by

ilikemandalin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

It 1

The document contains a Java program that demonstrates various data types, arithmetic operations, and control flow structures such as loops and conditionals. It includes commented-out sections for variable declarations, basic arithmetic, and user input handling. The main functionality focuses on calculating the sum of even numbers within a specified range using the 'findSumInRange' method.

Uploaded by

ilikemandalin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;

public class Main {


public static void main(String[] args) {
/*byte b = 2;
short s = 120;
int i = 400;
long l = 892342389;
float f = 4.3f;
double d = 5.1;
char c = 'a';
boolean bl = true;

System.out.println("byte b is: " + b);


System.out.println("short s is: " + s);
System.out.println("int i is: " + i);
System.out.println("long l is: " + l);
System.out.println("float f is: " + f);
System.out.println("double d is: " + d);
System.out.println("char c is: " + c);
System.out.println("boolean bl is: " + bl);*/

/* int a = 6;
int b = 5;
int c = a + b;
System.out.println(c);

int e = 7;
int f = 3;
int d = e - f;
System.out.println(d);*/

/* int resultOfSum = sum(6, 5);


System.out.println(resultOfSum);

int resultOfDiff = diff(7, 3);


System.out.println(resultOfDiff);*/

/*Scanner scanner = new Scanner(System.in);

int a = scanner.nextInt();
int b = scanner.nextInt();

if (a > b) {
System.out.println("a is greater than b");
} else if (a < b) {
System.out.println("a is lesser than b");
} else {
System.out.println("a is equal to b");
}*/

//int counter = 1;
/*System.out.println(++counter);
System.out.println(counter);*/
//counter = counter + 1;
//counter++;
//++counter;
/*while (counter > 10) {
System.out.println("while loop: counter value is: " + counter);
counter = counter + 1;
}*/

/*do {
System.out.println("do-while loop: counter value is: " + counter);
counter = counter + 1;
} while (counter > 10);*/

/* for (int counter = 0; counter < 10; counter++) {


System.out.println("for loop: counter value is: " + counter);
}*/

/*int sumInRange = 0;
for (int var = 0; var <= 10; var++) {
sumInRange = sumInRange + var;
if (sumInRange > 20) {
System.out.println(var);
break;
}
}
System.out.println(sumInRange);*/

/*for (int counter = 0; counter < 10; counter++) {


System.out.print(counter + " ");
}

System.out.println();

for (int counter = 0; counter < 10; counter++) {


if (counter == 4) {
continue;
}
System.out.print(counter + " ");
}*/

Scanner scanner = new Scanner(System.in);


String s = "";

int c = scanner.nextInt();
int d = scanner.nextInt();
int sumInRange = findSumInRange(c, d);
/*if (d < c) {
sumInRange = findSumInRange(d, c);
} else {
sumInRange = findSumInRange(c, d);
}*/
System.out.println(sumInRange);

public static int findSumInRange(int a, int b) {


int sumInRange = 0;
for (int i = Math.min(a, b); i <= Math.max(a, b); i++) {
if (i % 2 == 0) {
sumInRange = sumInRange + i;
}
}
return sumInRange;
}

public static int sum(int a, int b) {


//int c = a + b;
return a + b;
}

public static int diff(int a, int b) {


return a - b;
}
}

You might also like