Вы находитесь на странице: 1из 16

ACT 1 HELLOWORLD

public class Hello { public static void main(String[]args){ System.out.println("Hello World"); } }

ACT 2 VARIABLE
public class Variable {

public static void main(String[] args) { int number=10; char letter='s'; boolean result=true; String str="hi"; System.out.println("number="+number); System.out.println("letterr="+letter); System.out.println("result="+result); System.out.println("String="+str); } }

ACT 3 AMAHYMN
public class Hymm {

public static void main(String[] args) {

System.out.println("Dear Alma Matter); System.out.println("You have given us arms"); System.out.println("For the battle of life"); System.out.println("And the conquest of our dreams"); System.out.println("Oh dear AMA"); System.out.println("You have sharpened our minds"); System.out.println("We will triumph by which"); System.out.println("The toast is for you");

ACT 4 AVERAGE
public class Average {

public static void main(String[] args) { int num1=10,num2=20,num3=45,average; System.out.println("num1="+num1); System.out.println("num2="+num2); System.out.println("num3="+num3); average=(num1+num2+num3)/3; System.out.println("average is="+average); }

PRELIM GRADE
public class Main {

public static void main(String[] args) { double Q1=85; double Q2=85; double Cs=100; double me=80; double PG=0; System.out.println("Q1=85"+Q1);

System.out.println("Q2=85"+Q2); System.out.println("CS=100"+Cs); System.out.println("me=80"+me); PG=(Q1*.20)+(Q2*.20)+(Cs*.10)+(me*.50); System.out.println("your prelim grade is="+PG);

GREATEST VALUE
public class Main { public static void main(String[] args){ int num1=10; int num2=23; int num3=5; int max=0; max=(num1>num2)?num1:num2; max=(max>num3)?max:num3; System.out.println("number1="+num1);

System.out.println("number2="+num2); System.out.println("number3="+num3); System.out.println("The highest num is="+max); } }

LAST THREE WORD


import java.io.*; public class Main { public static void main(String[] args) { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); String Firstword=""; String Second=""; String Thirdword=""; try{ System.out.println("EnterWord1"); Firstword=reader.readLine(); System.out.println("EnterWord2"); Second=reader.readLine(); System.out.println("EnterWord3"); Thirdword=reader.readLine();

} catch(IOException e){ System.out.print("Error in geting input"); } System.out.println("firstWord"+""+"secondWord"+""+"thirdWord");

NUMWORD
import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { String msg=""; int input=0; input=Integer.parseInt(JOptionPane.showInputDialog("Enter number")); if(input==1); else if(input==2); else if(input==3); else if(input==4); else if(input==5); else msg="one";

msg="two"; msg="three"; msg="four"; msg="five"; msg="Invalid number"; JOptionPane.showMessageDialog(null,msg); } }

HUNDREDNAMES USING WHILE


import java.io.*; public class Main { public static void main(String[] args) { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); String name=""; int counter=0; try{

System.out.print("Enter name:"); name=reader.readLine(); }catch(Exception e){ System.out.println("Invalid Input"); System.exit(0);

}while(counter<100){ System.out.println(name); counter ++; }

} }

HUNDREDNAMES USING DO WHILE


import java.io.*; public class Main { public static void main(String[] args) { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); String name=""; int counter=0; try{ System.out.print("Enter name:"); name=reader.readLine();

}catch(Exception e){ System.out.println("Invalid Input"); System.exit(0); do{ System.out.println(name); counter++; }while(counter<100); }

} }

HUNDREDNAMES USING FOR


import java.io.*; public class Main { public static void main(String[] args) { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); String name=""; try{ System.out.print("Enter name"); name=reader.readLine(); }catch(Exception e){ System.out.println("Invalid input"); System.exit(0);

} for(int counter=0;counter<100;counter++){ System.out.println(name);

POWERS USING FOR


import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { int base=0; int exp=0; int power=0; int counter=0; base=Integer.parseInt(JOptionPane.showInputDialog("Base")); if(exp<0){ JOptionPane.showMessageDialog(null,"Positive numbers only please"); System.exit(0);

} for(counter=0;counter<exp;counter++){ power=power*base; } JOptionPane.showMessageDialog (null,base+"to the"+exp+"is"+power);

POWER USING DO WHILE


import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { int base=0; int exp=0;

int power=0; int counter=0; base=Integer.parseInt(JOptionPane.showInputDialog("Base")); exp=Integer.parseInt(JOptionPane.showInputDialog("Exponent")); if(exp<0){ JOptionPane.showInputDialog(null,"Positive numbers only Please"); System.exit(0); } do{ if(exp!=0) power=power*base; counter ++; }while(counter<exp); JOptionPane.showMessageDialog(null,base+"to the"+exp+"is"+power); } }

POWERS USING WHILE


import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { int base=0; int exp=0; int power=0; int counter=0; base=Integer.parseInt(JOptionPane.showInputDialog("Base")); exp=Integer.parseInt(JOptionPane.showInputDialog("Exponent")); if(exp<0){ JOptionPane.showInputDialog(null,"Positive numbers only Please"); System.exit(0); } while(counter<exp){ power=power*base; counter++; } JOptionPane.showMessageDialog(null,base+"to the"+exp+"is"+power); } }

DAYS OF THE WEEK USING WHILE


public class Main {

public static void main(String[] args) { String[]days={"Sunday","Monday","Tuesday","Thursday","Friday","Saturday",}; int counter=0; while(counter<days.length){ System.out.println(days[counter]); counter++;

DAYS OF THE WEEK USING DO WHILE

public class Main {

public static void main(String[] args) { String[]days={"Sunday","Monday","Tuesday","Thursday","Friday","Saturday",}; int counter=0; do{ System.out.println(days[counter]); counter++; }while(counter<days.length); }

Вам также может понравиться