Sunteți pe pagina 1din 4

Nofuente, Christian C. TTH/6:30-8:00 SOURCE CODE: package nofuente_looping; import java.io.

*;

September 21, 2011 Engr. Hubert Q. Temprosa

public class Looping { public static void main(String[] args) throws IOException { BufferedReader in= new BufferedReader (new InputStreamReader(System.in)); String ans; do { char cho='y'; System.out.println("1: FOR\n2: WHILE\n3: Do...While"); System.out.print("Select the LOOPING to be use:"); String L=in.readLine(); switch(L.charAt(0)) { case '1': for(cho='y'; cho=='y'||cho=='Y'; ) { System.out.println("1: Circle\n2: Square\n3: Triangle"); System.out.print("Select the Shape:"); String S=in.readLine(); System.out.print("FOR LOOP"); switch(S.charAt(0)) { case '1': System.out.print("\nEnter radius: "); String R = in.readLine(); int r= Integer.parseInt(R); System.out.print("\nThe area of the circle is "+(3.1416*r*r)); break; case '2': System.out.print("\nEnter Side: "); String Si = in.readLine(); int s= Integer.parseInt(Si); System.out.print("\nThe are of the square is "+(s*s)); break; case '3':

System.out.print("\nEnter Base: "); String B = in.readLine(); int b= Integer.parseInt(B); System.out.print("Enter Height: "); String H = in.readLine(); int h= Integer.parseInt(H); System.out.print("\nThe area of the Triangle is " +(b*h*0.5) ); break; } System.out.print("\n\nDo you still want to compute for shape?"); String CHO = in.readLine(); cho=CHO.charAt(0); }break; case '2': while(cho=='y'||cho=='Y') { System.out.println("1: Circle\n2: Square\n3: Triangle"); System.out.print("Select the Shape:"); String S=in.readLine(); System.out.print("WHILE LOOP"); switch(S.charAt(0)) { case '1': System.out.print("\nEnter radius: "); String R = in.readLine(); int r= Integer.parseInt(R); System.out.print("\nThe area of the circle is "+(3.1416*r*r)); break; case '2': System.out.print("\nEnter Side: "); String Si = in.readLine(); int s= Integer.parseInt(Si); System.out.print("\nThe are of the square is "+(s*s)); break; case '3': System.out.print("\nEnter Base: "); String B = in.readLine(); int b= Integer.parseInt(B); System.out.print("Enter Height: "); String H = in.readLine(); int h= Integer.parseInt(H); System.out.print("\nThe area of the Triangle is " +(b*h*0.5) ); break; } System.out.print("\n\nDo you still want to compute for shape?");

String CHO = in.readLine(); cho=CHO.charAt(0); }break; case '3': String choice; do { System.out.println("1: Circle\n2: Square\n3: Triangle"); System.out.print("Select the Shape:"); String S=in.readLine(); System.out.print("DO...WHILE LOOP"); switch(S.charAt(0)) { case '1': System.out.print("\nEnter radius: "); String R = in.readLine(); int r= Integer.parseInt(R); System.out.print("\nThe area of the circle is "+(3.1416*r*r)); break; case '2': System.out.print("\nEnter Side: "); String Si = in.readLine(); int s= Integer.parseInt(Si); System.out.print("\nThe are of the square is "+(s*s)); break; case '3': System.out.print("\nEnter Base: "); String B = in.readLine(); int b= Integer.parseInt(B); System.out.print("Enter Height: "); String H = in.readLine(); int h= Integer.parseInt(H); System.out.print("\nThe area of the Triangle is " +(b*h*0.5) ); break; } System.out.print("\n\nDo you still want to compute for shape?"); choice=in.readLine(); }while(choice.charAt(0)=='y'||choice.charAt(0)=='Y');break; } System.out.print("\n\nDo you Still want to compute?"); ans=in.readLine(); }while(ans.charAt(0)=='y'||ans.charAt(0)=='Y'); } }

SAMPLE OUTPUT: 1: FOR 2: WHILE 3: Do...While Select the LOOPING to be use:1 1: Circle 2: Square 3: Triangle Select the Shape:3 FOR LOOP Enter Base: 4 Enter Height: 4 The area of the Triangle is 8.0 Do you still want to compute for shape?n Do you Still want to compute?y 1: FOR 2: WHILE 3: Do...While Select the LOOPING to be use:3 1: Circle 2: Square 3: Triangle Select the Shape:1 DO...WHILE LOOP Enter radius: 3 The area of the circle is 28.2744 Do you still want to compute for shape?n Do you Still want to compute?n BUILD SUCCESSFUL (total time: 55 seconds)

S-ar putea să vă placă și