Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 960 Bytes

File metadata and controls

43 lines (30 loc) · 960 Bytes

write a program to print numbers from 1 to 10 using for loop

class OneTOTen{
    public static void main(String args[]){

        for (int i = 1; i<10; i++){
            System.out.println(i);
        }
    }
}

Write a program to display numbers from 1 to 10 using while loop and do while loop Reading of for, while, do while loop from java T point

foreach loop

for-each loop is used to traverse array or collection in Java

  • It is easier to use than simple for loop because we do not need to increment the value

  • It works on element basis

  • It returns element one-by-one in the defined variable

class ForEach{
    public static void main(){
        int arr[] = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

        for(int i : arr){
            System.out.println(i);
        }
    }
}

ToDo

write a prog to check if the given no is prime or not in java

write a prog to check given no is armstrong or not