ForLoops
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
package ics3.other.ForLoops;
|
||||||
|
///Kuba Szatan
|
||||||
|
//2026-11-03
|
||||||
|
//Application 6a
|
||||||
|
|
||||||
|
|
||||||
|
import hsa.Console;
|
||||||
|
public class ForLoopsA{
|
||||||
|
Console c;
|
||||||
|
|
||||||
|
public ForLoopsA(){ // constructor method
|
||||||
|
c=new Console(25,100);
|
||||||
|
}
|
||||||
|
public void display(){
|
||||||
|
c.print("", 25);
|
||||||
|
c.println("Application 6a");
|
||||||
|
// c.print("The area is " + area);
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
|
||||||
|
c.print(i+1, 10);
|
||||||
|
c.print(i+3, 10);
|
||||||
|
c.print((i+1)*12, 10);
|
||||||
|
c.print(-(i + 4), 10);
|
||||||
|
c.print(30-i, 10);
|
||||||
|
c.println(i+9, 10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void main(String[] args){
|
||||||
|
ForLoopsA l=new ForLoopsA();
|
||||||
|
l.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package ics3.other.ForLoops;
|
||||||
|
///Kuba Szatan
|
||||||
|
//2026-11-03
|
||||||
|
//Application 6b
|
||||||
|
|
||||||
|
|
||||||
|
import hsa.Console;
|
||||||
|
public class ForLoopsB{
|
||||||
|
Console c;
|
||||||
|
|
||||||
|
public ForLoopsB(){ // constructor method
|
||||||
|
c=new Console(25,100);
|
||||||
|
}
|
||||||
|
public void display(){
|
||||||
|
c.print("", 25);
|
||||||
|
c.println("Application 6b");
|
||||||
|
// c.print("The area is " + area);
|
||||||
|
for (int i = 0; i < 20; i++) {
|
||||||
|
c.print("",i+3);
|
||||||
|
c.println("* * * *");
|
||||||
|
}
|
||||||
|
c.print("", 50);
|
||||||
|
c.print("Kuba Szatan");
|
||||||
|
}
|
||||||
|
public static void main(String[] args){
|
||||||
|
ForLoopsB l=new ForLoopsB();
|
||||||
|
l.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package ics3.other;
|
||||||
|
|
||||||
|
import hsa.Console;
|
||||||
|
public class Loops
|
||||||
|
{
|
||||||
|
Console c;
|
||||||
|
public Loops ()
|
||||||
|
{
|
||||||
|
c = new Console ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void display ()
|
||||||
|
{
|
||||||
|
|
||||||
|
c.println ("\n\nExample 1");
|
||||||
|
|
||||||
|
for (int i = 1 ; i <= 5 ; i++)
|
||||||
|
{
|
||||||
|
c.print (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
c.println ("\n\n\nExample 2");
|
||||||
|
|
||||||
|
for (int i = 1 ; i <= 5 ; i++)
|
||||||
|
{
|
||||||
|
c.print (i); //numbers printed on one line
|
||||||
|
}
|
||||||
|
|
||||||
|
c.println ("\n\nExample 3");
|
||||||
|
|
||||||
|
for (int i = 1 ; i < 1000000 ; i *= 2)
|
||||||
|
{
|
||||||
|
c.print (i + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
c.println ("\n\nExample 4");
|
||||||
|
|
||||||
|
for (int i = 10 ; i >= 1 ; i--)
|
||||||
|
{
|
||||||
|
c.print (i + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
c.println ("\n\nExample 5");
|
||||||
|
|
||||||
|
for (int i = 1 ; i < 15 ; i++)
|
||||||
|
{
|
||||||
|
c.print (i * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
c.println ("\n\nExample 6");
|
||||||
|
|
||||||
|
for (int i = 100 ; i > 0 ; i /= 2)
|
||||||
|
{
|
||||||
|
c.print (i + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
c.println ("\n\nExample 7");
|
||||||
|
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 1 ; i <= 10 ; i++)
|
||||||
|
{
|
||||||
|
sum += i;
|
||||||
|
c.print (sum + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
c.println ("\n\nExample 8");
|
||||||
|
|
||||||
|
int base = 1;
|
||||||
|
for (int i = 0 ; i < 12 ; i++)
|
||||||
|
{
|
||||||
|
base *= 2;
|
||||||
|
c.print (base + " ");
|
||||||
|
}
|
||||||
|
int num;
|
||||||
|
for (num = 5; num < 14; num+=2) {
|
||||||
|
c.print(num,20);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Test the following code and compare output
|
||||||
|
public static void main (String[] args)
|
||||||
|
{
|
||||||
|
|
||||||
|
Loops l = new Loops ();
|
||||||
|
l.display ();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user