This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.qacaffe.examples.ControlStatements; | |
import java.util.Scanner; | |
public class IfElse { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Please enter a number to test whether the given number is bigger than 20."); | |
int number = scanner.nextInt(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class OddEven { | |
public static void main(String[] args) { | |
//Scanner class object is used to read input from the user. | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("Please enter a number : "); | |
int value = scanner.nextInt(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MaximumOfThreeNumbers { | |
public static void main(String[] args) { | |
//variable declaration | |
int n1, n2, n3, maximum; | |
//Input from user | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("Enter number 1 : "); | |
n1 = scanner.nextInt(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArrayLength { | |
public static void main(String[] args) { | |
int[] myArray = {1, 2, 3, 4, 556, 4534, 354, 55}; | |
System.out.println("Length of myArray is : " + myArray.length); | |
} | |
} | |
/* | |
Output : | |
Length of myArray is : 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class ArrayExample2 { | |
public static void main(String[] args) { | |
int[] a = {1, 2, 3}; | |
int[] b = new int[5]; | |
Scanner scanner = new Scanner(System.in); | |
for (int i = 0; i < a.length; i++) { | |
b[i] = a[i]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArrayExample { | |
public static void main(String[] args) { | |
int[] anArray = new int[10]; | |
for (int i = 0; i < 10; i++) { | |
anArray[i] = i; | |
System.out.print(anArray[i] + " "); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class ReadAndSortValues { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int[] value = new int[5]; | |
int count = 1, temp; | |
//To take the number of marks entered by the users. | |
for (int i = 0; i < 5; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class ReverseNumberWhileLoop { | |
public static void main(String[] args) { | |
int num, reverse = 0, result; //declaring variable | |
//Take input from user | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("Enter number to reverse."); | |
num = scanner.nextInt(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class ReverseNumberForLoop { | |
public static void main(String[] args) { | |
int num, reverse = 0; //declaring variable | |
//Take input from user | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("Enter number to reverse."); |
NewerOlder