You are on page 1of 8

PRINTING A SENTENCE SOURCE CODE

class A{ public static void main(String args[]){ System.out.println("Sri Manakula Vinayagar Engineering College "); System.out.println("CSE "); System.out.println("IT"); System.out.println("ECE "); System.out.println("EEE "); } }

SAMPLE INPUT AND OUTPUT

Sri Manakula Vinayagar Engineering College CSE IT ECE EEE

SAMPLE INPUT AND OUTPUT

USING SWITCH CASE Marks of student is 80 Grade is Distinction

SAMPLE INPUT AND OUTPUT GETTING INPUTS enter 2 values 40 the first integer is 40 40 the second integer is 40 the addition of two integers is 80

USING SWITCH CASE SOURCE CODE

class B{ public static void main(String args[]) { int a,index,marks; String grade; marks=80; index=marks/10; System.out.println("USING SWITCH CASE"); System.out.println ("Marks of student is " + marks); System.out.println("Grade is "); switch(index) { case 10: case 9: grade = "honours outstanding"; break; case 8: grade = distinction; break; case 7:

case 6: grade = "first class"; break;

case 5: grade = "second class"; break; case 4: grade = "third class"; break; default: grade = "fail"; break; }

System.out.print(grade); } }

GETTING INPUT FROM USER SOURCE CODE import java.io.*; class Input{ public static void main(String args[]){ String a,b; int x,y,c; System.out.println("GETTING INPUTS "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try{ System.out.println("enter 2 values"); a = br.readLine(); x = Integer.parseInt(a); System.out.println("the first integer is " + a); b = br.readLine(); y = Integer.parseInt(b); System.out.println("the second integer is " + b); c=x+y; System.out.println("the addition of two integers is "+ c); } catch(IOException e) { System.out.println("caught exception error"+e); } } }

USING ARRAYS

SOURCE CODE class Array{ public static void main(String args[]){ int i,j,k; k=1; int key[][] =new int[3][3]; System.out.println("USING ARRAYS TO ASSIGN & PRINT VALUES"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { key[i][j] =k; k++; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { System.out.println("a["+i+"]["+j+"] = "+key[i][j]); } } } }

SAMPLE INPUT AND OUTPUT USING ARRAYS TO ASSIGN & PRINT VALUES a[0][0] = 1 a[0][1] = 2 a[0][2] = 3 a[1][0] = 4 a[1][1] = 5 a[1][2] = 6 a[2][0] = 7 a[2][1] = 8 a[2][2] = 9

SAMPLE INPUT AND OUTPUT arithmetic operations the given two integers are 20 and 10 ADDITION the sum of two integers is 30 SUBTRACTION the difference of two integers is 10 MULTIPLICATION the product of two integers is 200 DIVISION the division of two integers is 2

ARITHMETIC OPERATIONS SOURCE CODE class Arith{ public static void main(String args[]){ int i,j,k; i=20; j=10; System.out.println("arithmetic operations"); System.out.println("the given two integers are 20 and 10"); System.out.println("\nADDITION"); System.out.println("the sum of two integers is "+(i+j)); System.out.println("\nSUBTRACTION"); System.out.println("the difference of two integers is "+(i-j)); System.out.println("\nMULTIPLICATION"); System.out.println("the product of two integers is "+(i*j)); System.out.println("\nDIVISION"); System.out.println("the division of two integers is "+(i/j)); } }

You might also like