Tuesday, 26 July 2016

Write a program to print all numbers from 1 to 30. If the number is a multiple of 13, print the string "lucky number" instead of the number.

import java.util.*;
class Lucky{
    public static void main(String args[]){
        Scanner m=new Scanner(System.in);
        String s="lucky number";
        for(int i=1;i<=30;i++){
            if(i%13==0){
            System.out.print(s+" ");
        }
        else
            System.out.print(i+" ");
        }
    }
}

No comments: