Lec 3 _ Intro to Java contd.pptx
Lec 3 _ Intro to Java contd.pptx
of Electrical &
Computer Engineering (ECE)
Output:
All rows contain same columns Each row contain different columns
if(i == d/2) {
if(j < 20) a = b;
if(k > 100) c = d;
else a = c;
}
else a = d;
Another Example
int i=100, j=200;
System.out.println(“Midpoint: ” + i);
for( ; !done; ) {
System.out.println("i is " + i);
if(i == 10) done = true;
i++;
}
int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sum = 0;
for(int i=0; i < 10; i++) sum += nums[i];
int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sum = 0;
for(int x: nums) sum += x;
* You can use the break statement if want to finish the loop early
class InputTest{
public static void main(String args[]){
Scanner scan = new Scanner (System.in);
System.out.println(“Enter an interger:”);
int n = scan.nextInt();