FTSC 3103 Programming: Name: Muhammad Nur Hakimi Bin Abd Jalil No - Matrix: 16FA03028 Lect: Siti Azrehan BT Aziz
FTSC 3103 Programming: Name: Muhammad Nur Hakimi Bin Abd Jalil No - Matrix: 16FA03028 Lect: Siti Azrehan BT Aziz
FTSC 3103 Programming: Name: Muhammad Nur Hakimi Bin Abd Jalil No - Matrix: 16FA03028 Lect: Siti Azrehan BT Aziz
PROGRAMMING
LAB EXERCISE 6
int y;
int x = 1;
int total = 0;
Example 1b
import java.util.Scanner;
public class Lab6_Example1b {
int data;
int sum = 0;
Scanner MyInput = new Scanner (System.in);
while (data != 0)
{
sum += data;
System.out.print("Enter an int value, the program exits if the input is 0: ");
data = MyInput.nextInt();
}
System.out.println("The sum is "+sum);
}
}
EXAMPLE 2A
import java.util.Scanner;
width = input.nextInt();
for(a=1;a<=length;a++)
{
System.out.println();
for(b=1;b<=width;b++)
{
System.out.print("*");
}
}
}
EXAMPLE 2B
System.out.print(num);
System.out.println("");
}
}
}
EXAMPLE 3A
int sum = 0;
int item = 0;
do
{
item ++;
sum += item;
}
EXERCISE 1
import java.util.Scanner;
width = input.nextInt();
for(a=1;a<=length;a++)
{
System.out.println();
for(b=1;b<=width;b++)
System.out.print("@");
}
}
}
}
EXERCISE 2
public class Lab_6 {
int miles;
double km = 0;
System.out.println("Miles Kilometers");
System.out.println("-----------------------------");
for(miles=1;miles<=10;miles++)
km = km + kilo ;
System.out.println(miles+" "+km);
System.out.println("-----------------------------");
}
}
}
CONCLUSION
In this lab exercise, I have learned how to write coding using statement and while in this program.
Hope this lab will help me in better future to write better code.