Created
November 14, 2013 05:17
-
-
Save JorgeOlvera/7461791 to your computer and use it in GitHub Desktop.
For Looping
This file contains hidden or 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.io.*; | |
import java.util.Scanner; | |
public class AsteriskTriangle { | |
public static void main (String [] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.println("Type an integer: "); | |
int nmbr = input.nextInt(); | |
System.out.println("Here is your tree!"); | |
for (int i = 1; i <= nmbr; i++) | |
{ | |
for (int h = 0; h < i; h++) | |
{ | |
System.out.print("*"); | |
} | |
} | |
} | |
} |
This file contains hidden or 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 ClassifyNumbers { | |
public static void main(String [] args) { | |
int nmbrs, number, lowLimit, highLimit, count; | |
int sum = 0; | |
int total = 0; | |
Scanner input = new Scanner(System.in); | |
System.out.println("How many numbers:"); | |
nmbrs = input.nextInt(); | |
System.out.println("Low Limit:"); | |
lowLimit = input.nextInt(); | |
System.out.println("High Limit:"); | |
highlimit = input.nextInt(); | |
for (count = 1; count <= nmbrs; count++) | |
{ | |
System.out.println("Type first number"); | |
number = input.nextInt(); | |
if (number >= lowlimit && number <= highlimit) | |
{ | |
System.out.println("The number is within range"); | |
sum = sum + numero; | |
total = total + 1; | |
} | |
else | |
System.out.println("Number is out of range"); | |
} | |
System.out.println(+ total + "numbers within range"); | |
System.out.println("The sum is" + sum "."); | |
} | |
} |
This file contains hidden or 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 PerfectNumber { | |
public static void main(String [] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.println("How many numbers:") | |
int amount = input.nextInt(); | |
for (int i = 1; i <= amount; i ++) { | |
System.out.println("Type number #" + i); | |
int number = input.nextln(); | |
int result = 0; | |
for (int h = 1; h < number; h ++) | |
{ | |
if (number % h == 0){ | |
result = result + h; | |
} | |
} | |
if (result == number) System.out.println("The number is perfect."); | |
else System.out.println("The number is not perfect."); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment