Quiz for divide and remainder operator - Java Language Basics

Java examples for Language Basics:float

Introduction

Write a program that displays two numbers

Use the / and % operators to display the result and remainder after they are divided.

Use the \t character escape code to make a tab character separate the result and remainder.

Demo Code


public class Main {
    public static void main(String[] arguments) {
        float number1 = 15;
        float number2 = 6;
        float result = number1 / number2;
        float remainder = number1 % number2;
        System.out.println(number1 + " divided by " + number2);
        System.out.println("\nResult\tRemainder");
        System.out.println(result + "\t" + remainder);
    }/*ww w.  j  ava 2  s .  c o m*/
}

Result


Related Tutorials