Practice question for java learner

0

Basic question 1

//1. Write a Java program to print 'Hello' on screen and your name on a separate line.

  1. public class practice1 {
        public static void main(String[] args) {
            System.out.println( "rakesh" );
        }
       
    }

  2. import java.util.Scanner;
    public class practice2 {
        //Write a Java program to print the sum of two numbers.
        // public static void main(String[] args) {
        //     int i=5, y=8;
        //     System.out.println(i+y);
           
        // }
        // input methode

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            System.out.print("=");
            int b =sc.nextInt();
            System.out.print(a+b);
            sc.close();
        }
       
    }

  3. public class practice3 {
        //Write a Java program to divide two numbers and print them on the screen.
        // public static void main(String[] args) {
        //     int a=50, b=3;
        //     System.out.println(a/b);      
        // }
       

    // output 16 because here note is use float type and below try to use float type
    public static void main(String[] args) {
        float a=33,b=10;
        System.out.println(a/b);
    }
    }
    // out is 3.3 because i am also use float type date type

  4. // 4. Write a Java program to print the results of the following operations.
    // Test Data:
    // a. -5 + 8 * 6
    // b. (55+9) % 9
    // c. 20 + -3*5 / 8
    // d. 5 + 15 / 3 * 2 - 8 % 3
    import java.util.Scanner;
    public class practice4 {
        public static void main(String[] args) {
            // A. I am try to solve using input methode this question
            Scanner sc = new Scanner (System.in);
            System.out.println("Enter your input");
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            System.out.println(a+b*c);
            sc.close();
            // output is 43
            //b.try to solve using declare deta type
            int d =(55+9), e=9;
            System.out.println(d%e);
            //out put 1
            //C.
            int f = 20, g=-3*5, h=8;
            System.out.println(f+g/h);
            //out put 19
            //d.
            int i =5,j=15/3*2, k=8%3;
            System.out.println(i+j-k);
            //out put is 13

           

           
        }
    }

Post a Comment

0Comments
Post a Comment (0)