From 991c4407292584854714ede1113ebbacea0d01dc Mon Sep 17 00:00:00 2001 From: Chinmay Chandak Date: Tue, 31 Oct 2017 23:21:56 +0530 Subject: [PATCH] restructured the code --- JAVA/Input.java | 11 ++++++----- JAVA/addcomplex.java | 34 +++++++++++++++++++++++----------- JAVA/grade.java | 6 +++--- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/JAVA/Input.java b/JAVA/Input.java index 601733d..c06908c 100644 --- a/JAVA/Input.java +++ b/JAVA/Input.java @@ -6,9 +6,10 @@ import java.util.*; class input { - static void scanner_input() + static void scanner_input () { Scanner sc = new Scanner(System.in); + System.out.println("Enter a string(using Scanner)"); String s = sc.nextLine(); System.out.println("Entered String is : "+s); @@ -17,7 +18,7 @@ static void scanner_input() System.out.println("Entered number is : "+n); } - static void buffered_input() throws IOException + static void buffered_input () throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -29,7 +30,7 @@ static void buffered_input() throws IOException System.out.println("Entered number is : "+n); } - static void right_shift() + static void right_shift () { Scanner sc = new Scanner(System.in); System.out.println("Enter a number"); @@ -37,7 +38,7 @@ static void right_shift() System.out.println("After shifting :"+(num>>3)); } - public static void main(String[] args) + public static void main (String[] args) { String s = args[0]; double d = Double.parseDouble(args[1]); @@ -51,7 +52,7 @@ public static void main(String[] args) { buffered_input(); } - catch(Exception e) + catch (Exception e) { System.out.println(e); } diff --git a/JAVA/addcomplex.java b/JAVA/addcomplex.java index 8e14e69..ded4260 100644 --- a/JAVA/addcomplex.java +++ b/JAVA/addcomplex.java @@ -5,17 +5,23 @@ class number { int real,im; - number() - { real=0; im=0; } - number(int r,int i) + + number () + { + real=0; im=0; + } + + number (int r,int i) { real=r; im=i; } - void display() + + void display () { System.out.println(" Number is "+real+"+"+im+"i"); } - number add(number num) + + number add (number num) { number answer = new number(); answer.real =real+num.real; @@ -26,21 +32,27 @@ number add(number num) class addcomplex { - public static void main(String[] args) + public static void main (String[] args) { Scanner sc = new Scanner(System.in); + System.out.println("Enter real part of 1st number "); - int realnum=sc.nextInt(); + int realnum = sc.nextInt(); + System.out.println("Enter imaginary part of 1st number "); - int imaginary=sc.nextInt(); + int imaginary = sc.nextInt(); number c1 = new number(realnum,imaginary); + System.out.println("Enter real part of 2nd number "); - int realnum1=sc.nextInt(); + int realnum1 = sc.nextInt(); + System.out.println("Enter imaginary part of 2nd number "); - int imaginary1=sc.nextInt(); - number c2 = new number(realnum1,imaginary1); + int imaginary1 = sc.nextInt(); + + number c2 = new number(realnum1, imaginary1); number c3 = new number(); c3 = c1.add(c2); + c3.display(); } } \ No newline at end of file diff --git a/JAVA/grade.java b/JAVA/grade.java index 33b3ea6..988b5f4 100644 --- a/JAVA/grade.java +++ b/JAVA/grade.java @@ -4,18 +4,18 @@ import java.util.*; class grade { - public static void main(String[] args) + public static void main (String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter marks of student"); int marks = sc.nextInt(); - if(marks > 100) + if (marks > 100) marks = -1; else marks = marks/10; - switch(marks) + switch (marks) { case 10: case 9: System.out.println("Grade : A");