Question-1: Write a Java program that loops 1-50 and print foo for every multiple of 3, bar for every multiple of 5 and baz for every multiple of 3 and 5.
Series Program:
public class Series{
public static void main(String[]args){
for(int i=1;i<=50;i++){
System.out.print(i);
if(i%3==0 && i%5==0)
System.out.print(”−baz”);
else if(i%3==0)
System.out.print(”−foo”);
else if(i%5==0)
System.out.print(”−bar”);
System.out.println();
}
}
}
Series Program:
public class Series{
public static void main(String[]args){
for(int i=1;i<=50;i++){
System.out.print(i);
if(i%3==0 && i%5==0)
System.out.print(”−baz”);
else if(i%3==0)
System.out.print(”−foo”);
else if(i%5==0)
System.out.print(”−bar”);
System.out.println();
}
}
}
0 comments:
Post a Comment