The Berlin clock is a clock that tells the time using a series of illuminated coloured blocks.
- the top lamp blinks to show seconds-it is illuminated on even seconds and off on odd seconds.
- The next two rows represent hours. The upper row represents 5 hour blocks and is made up of 4 red lamps. The lower row represents 1 hour blocks and is also made up of 4 red lamps.
- The final two rows represent the minutes. The upper row represents 5 minute blocks, and is made up of 11 lamps- every third lamp is red, the rest are yellow. The bottom row represents 1 minute blocks, and is made up of 4 yellow lamps.
package rakesh;
import java.util.Scanner;
public class Digital
{
public static void main(String args[])
{
System.out.println("CONVERT DIGITAL TIME TO BERLIN TIME");
System.out.println("Enter time in hh:mm:ss Format");
Scanner sc=new Scanner(System.in);
sc.nextLine();
String Time=sc.nextLine();
String arr[]=Time.split(":");
int red1=Integer.parseInt(arr[0])/5;
int red2=Integer.parseInt(arr[0])%5;
int yellowred=Integer.parseInt(arr[1])/5;
int yellowlight=Integer.parseInt(arr[1])%5;
if(Integer.parseInt(arr[2])%2==0)
System.out.println("Y");
else
System.out.println("O");
for(int i=0;i<red1;i++)
System.out.print("R");
for(int i=0;i<(4-red1);i++)
System.out.print("O");
System.out.println();
for(int i=0;i<red2;i++)
System.out.print("R");
for(int i=0;i<(4-red2);i++)
System.out.print("O");
System.out.println();
for(int i=1;i<=yellowred;i++)
{
if(i%3==0)
System.out.print("R");
else
System.out.print("Y");
}
for(int i=0;i<(11-yellowred);i++)
System.out.print("O");
System.out.println();
for(int i=0;i<yellowlight;i++)
System.out.print("Y");
for(int i=0;i<4-yellowlight;i++)
System.out.print("O");
}
}
No comments:
Post a Comment